or ...
sapply(m,function(x) table(factor(x, levels=c(NA, 1:4), exclude=NULL)))
On Fri, Sep 19, 2008 at 12:59 PM, Ralikwen <[EMAIL PROTECTED]> wrote:
>
> 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
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(f
Hi
Here is an alternative solution which will include count of the NA. It
may not be "formally" correct, but it seems to work:
> mapply(function(x) table(factor(ifelse(is.na(x), "NA", x),
levels=c("NA",1,2,3,4))), m)
x1 x2 x3
NA 3 4 0
1 5 0 5
2 3 3 5
3 3 5 4
4 3 5 3
>
H
> I have a dataframe like this:
>
> 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,2,2,2,2,3,3,3,3,4,4,4,1,2)
> m<-data.frame(x1,x2,x3)
>
> I would like to create a frequency table like this:
>
> x1 x2 x3
> NA
> 1
>
Dear R users,
I have a dataframe like this:
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,2,2,2,2,3,3,3,3,4,4,4,1,2)
m<-data.frame(x1,x2,x3)
I would like to create a frequency table like this:
x1 x2 x3
NA
1
2
3
4
whe
5 matches
Mail list logo