[R] unwanted coercion using apply

2011-05-22 Thread Jeroen Ooms
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,

Re: [R] unwanted coercion using apply

2011-05-22 Thread Peter Ehlers
On 2011-05-21 23:11, Jeroen Ooms wrote: 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

Re: [R] unwanted coercion using apply

2011-05-22 Thread Jeroen Ooms
apply() operates on arrays and a data frame will be coerced to a matrix (which requires all elements to be of the same type). This is documented in ?apply. Thanks, I was not aware of that. I implicitly assumed there would be a specific apply.data.frame. This may not be elegant, but why

Re: [R] unwanted coercion using apply

2011-05-22 Thread David Winsemius
On May 22, 2011, at 3:22 PM, Jeroen Ooms wrote: apply() operates on arrays and a data frame will be coerced to a matrix (which requires all elements to be of the same type). This is documented in ?apply. Thanks, I was not aware of that. I implicitly assumed there would be a specific

Re: [R] unwanted coercion using apply

2011-05-22 Thread David Winsemius
On May 22, 2011, at 2:11 AM, Jeroen Ooms wrote: 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

Re: [R] unwanted coercion using apply

2011-05-22 Thread David Winsemius
On May 22, 2011, at 3:40 PM, David Winsemius wrote: On May 22, 2011, at 2:11 AM, Jeroen Ooms wrote: 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