On 2007-July-30 , at 12:20 , Prof Brian Ripley wrote: > On Mon, 30 Jul 2007, jiho wrote: >> A recent (in 2.5 I suspect) change in R is giving me trouble. I want >> to apply a function (tolower) to all the columns of a data.frame and >> get a data.frame in return. >> Currently, on a data.frame, both apply (for arrays) and lapply (for >> lists) work, but each returns its native class (resp. matrix and >> list): >> >> apply(mydat,2,tolower) # gives a matrix >> lapply(mydat,tolower) # gives a list >> and >> sapply(mydat,tolower) # gives a matrix > > which is exactly what R 2.0.0 did, so no recent(ish) change at all. > >> If I remember well, apply did not used to work on data.frames and >> lapply returned a data.frame when it was provided with one, with the >> same properties (columns classes etc). At least this is what my code >> written with R 2.4.* suggests. > > apply has coerced data frames for many years and lapply always > returned a list. The solution has always been > > mydat[] <- lapply(mydat,tolower)
sorry about that, my previous code was misleading and indeed your code above does exactly what I need. I should have tested this a bit further before posting. I was just afraid to install two different R versions I guess. thank you again. JiHO --- http://jo.irisson.free.fr/ ______________________________________________ R-help@stat.math.ethz.ch 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.