Will not just apply(mydf, 2 table) 
give you what you want in a list format?


--- [EMAIL PROTECTED] wrote:

> Dear list,
> 
> I have a data.frame with nine categorical variables
> (0,1,2 and NAs) 
> that I would like to get the number of events for
> each of them. I can 
> extract this using summary() for each variable at a
> time with the 
> as.factor()argument (otherwise it will get me the
> mean value):
> 
> >summary(as.factor(mydf[,3]))
>  0    1    2 NA's 
>  194   67    4    2
> 
> Trying to use apply() to get this for all the
> columns of the 
> data.frame I cannot use as.factor because it works
> with vectors and 
> not data.frames.
> 
> Can anyone help me? Maybe a for loop would be good
> in this case 
> instead, although I learnt that for loops are not
> recommended? 
> 
> Thanks in advance,
> 
> David
> 
> ______________________________________________
> R-help@r-project.org mailing list
> 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.
> 



      Looking for the perfect gift? Give the gift of Flickr!

______________________________________________
R-help@r-project.org mailing list
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.

Reply via email to