【发布时间】:2020-10-14 06:58:54
【问题描述】:
我正在尝试使用 tapply() 进行一些描述性分析,并使用 R 中的 mtcars 数据集。
所以问题是:
> table(mtcars$carb)
1 2 3 4 6 8
7 10 3 10 1 1
> tapply(mtcars$carb,list(mtcars$vs,mtcars$am),function(x){length(x)})
0 1
0 12 6
1 7 7
上面的行有效,但下面的行没有:
> tapply(mtcars$carb,list(mtcars$vs,mtcars$am),function(x){table(x)})
0 1
0 Integer,3 Integer,4
1 Integer,3 Integer,2
通过在 mtcars$carb 上使用 tapply,我希望从 vs 和 am 中获得四种组合中的每一种的表。知道出了什么问题吗?非常感谢。
【问题讨论】:
-
table(mtcars$carb, mtcars$vs, mtcars$am)?