I am trying to use tapply() for some descriptive analysis, with the mtcars dataset in R.
So the problem is:
> 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
The above line worked, but the line below didnt:
> tapply(mtcars$carb,list(mtcars$vs,mtcars$am),function(x){table(x)})
0 1
0 Integer,3 Integer,4
1 Integer,3 Integer,2
By using tapply on mtcars$carb, I expect to get the table for each of the four combinations from vs and am. Any idea what went wrong? Thank you very much.