Table
Hi Val, Does this help: library(plyr) ddply(as.data.frame(xc3), .variables = "xc1", summarise, d1 = sum(xc2 == 0), d2 = sum(xc2 == 1)) You could also try aggregate(xc3, by = list(xc1, xc2), FUN = sum) and modify the output. Best, Ulrik
On Thu, 11 Feb 2016 at 04:12 Val <valkremk at gmail.com> wrote:
Hi all,
I want create a frequency table using this :
xc1<- sample(c(1:10), 100, replace = TRUE)
xc2<- sample(c(0,1), 100, replace = TRUE)
xc3<- cbind(xc1,xc2)
tab1<- xc3[,list( d1=sum(xc2==0), d2=sum(xc2==1)),by=xc1]
but not working.
Error in `[.data.frame`(xc3, , list(d1 = sum(xc2 == 1), d2 = sum(xc2 == :
unused argument (by = xc1)
any idea?
I want the result like this
xc1 d1 d2
1 11 5
2 5 4
3 5 4
4 2 5
5 2 7
6 7 4
7 9 5
8 2 6
9 5 4
10 3 5
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.