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. ______________________________________________ R-help@r-project.org 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.