[R] apply problem

Seth Falcon sfalcon at fhcrc.org
Sat Apr 14 00:39:00 CEST 2007

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

More information about the R-help mailing list