[R] summary of categorical variables
John Kane
jrkrideau at yahoo.ca
Mon Jan 21 14:46:42 CET 2008
Will not just apply(mydf, 2 table)
give you what you want in a list format?
--- darteta001 at ikasle.ehu.es 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 at 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!
More information about the R-help
mailing list