[R] apply problem

Seth Falcon
Fri, 13 Apr 2007 22:39:00 -0000

aedin culhane <aedin at jimmy.harvard.edu> writes:

> Dear R-Help
> I am running apply on a data.frame containing factors and numeric
> columns.  It appears to convert are columns into as.character? Does it
> convert data.frame into matrix? Is this expected? I wish it to recognise
> numerical columns and round numbers.  Can I use another function instead
> of apply, or should I use a for loop in the case?

If you want to modify the data.frame object, a for loop will likely be
the best bet.  As noted in other replies, lapply will operate on the
columns of a data.frame since a data.frame is a list.  But the return
value will be a list, not a data.frame.

I think for loops get a bad wrap.  There are times when they are
appropriate and even optimal in R programming.

+ seth

--
Seth Falcon | Computational Biology | Fred Hutchinson Cancer Research Center