Skip to content
Prev 156546 / 398506 Next

frequency table across multiple variables

Hi,
I went for a slight alteration of your solution

x1<-c(1,2,3,4,NA ,NA ,NA, 3, 1, 1, 1, 1, 2, 2, 3, 4, 4)
x2<-c(2,3,4,3,4,3,4,2,2,3,4,NA,NA,NA,NA,4,3)
x3<-c(1,1,1,1,"aaa",2,2,2,3,3,3,3,4,4,4,1,2)
m<-data.frame(x1,x2,x3)
m<-replace(m,is.na(m),"NA")
levels=unique(as.vector(as.matrix(m)))
mapply(function(x) table(factor(levels)), m)

Many thanks for the help of both of you.
Bal?zs
Ivar Herfindal wrote: