I need to convert a dataframe to a record-structure, to be able to encode it
later in JSON. Suppose this is the data:

mydata <- data.frame(foo=1:3, bar=c("M","M","F"));

I would like to convert this to a unnamed list (json array) of key-value
pairs. For example like this:

apply(data.frame(foo=1:3, bar=c("M","M","F")),1,as.list)

However, when I do this, all the numeric values are converted to strings. I
don't understand why this is, because when I try to convert one record
simulataniously, this does not happen:

as.list(mydata[1,]);

I am not sure if this is indended behaviour or not, but is there an elegant
way to apply 'as.list' to all of the dataframe rows without coercing
everything to strings?


--
View this message in context: 
http://r.789695.n4.nabble.com/unwanted-coercion-using-apply-tp3541637p3541637.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.

Reply via email to