[R] Convert dataframe to array of records

Jeroen Ooms j.c.l.ooms at uu.nl
Sat Sep 5 18:20:02 CEST 2009


I would like to convert a dataframe to an array of lists, one for every
record. A natural choide is apply as.list to the rows. However, as it seems,
as.list() automatically converts all list elements to the same datatype. Eg:

myData <- data.frame(a="foo",b=as.logical(rbinom(10,1,.5)));
apply(myData,1,as.list);

In this output, all boolean values have been converted to character strings.
I don't understand why this happens; a list does not require that every
element is of the same datatype. Is there an easy way (ie avoid for-loops
etc) to convert the dataframe to an array of records, while keeping the
datatypes for every field? 

-----
Jeroen Ooms * Dept. of Methodology and Statistics * Utrecht University 

Visit  http://www.jeroenooms.com www.jeroenooms.com  to explore some of my
current projects.





 
-- 
View this message in context: http://www.nabble.com/Convert-dataframe-to-array-of-records-tp25310023p25310023.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list