[R] Q: changing the class of an object

From: Dave Evens <devens8765_at_yahoo.com>
Date: Fri 27 May 2005 - 02:30:56 EST

Dear All,

I have a list of dataframes, each cell in every dataframe (after I have cleaned up the dataframes) is either real or NA but have class character (I think). I would like to know how to change the class of every cell without using a for-loop. I currently have this

dataframes <- sapply(1: no.of.subs, function(k) apply(dataframes[[k]], 2, function(x) { if(class(x)=="character") x <- as(x, "numeric"); x }))

but this neither changes the cells to numeric nor keeps the dataframes in a list.

It creates one dataframe with number of rows=(no of rows in a dataframe*no of colums) and number of columns = no.of.subs

Can someone please help? Thanks in advance for any help.


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 Received on Fri May 27 02:38:51 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:07 EST