Re: [R] apply and table

2013-05-19 Thread arun
Hi, May be this helps: lev1<- unique(as.vector(z)) lapply(lapply(as.data.frame(z),factor,levels=lev1),table,lev1) #$V1  #    #  A B C   #A 1 1 0   #B 0 0 1   #C 0 0 0 # #$V2  #    #  A B C   #A 0 0 0   #B 1 0 0   #C 0 1 1 # #$V3  #    #  A B C   #A 1 0 0   #B 0 1 0   #C 0 0 1 #or library(plyr

Re: [R] apply and table

2013-05-19 Thread peter dalgaard
On May 19, 2013, at 16:22 , Jinsong Zhao wrote: > Hi there, > > I have the following code: > > z <- matrix(c("A", "A", "B", "B", "C", "C", "A", "B", "C"), ncol = 3) > apply(z, 2, table, c("A", "B", "C")) > > which give correct results. > > However, the following code: > > apply(z[,1,drop=FAL