[R] summary of categorical variables

darteta001 at ikasle.ehu.es darteta001 at ikasle.ehu.es
Mon Jan 21 14:08:04 CET 2008

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):

 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,


More information about the R-help mailing list