[R] toJSON question
Dieter Menne
dieter.menne at menne-biomed.de
Sat Dec 11 17:22:49 CET 2010
Santosh Srinivas wrote:
>
> I am trying to use RJSONIO
>
> I have:
> x <- c(0,4,8,9)
> y <- c(3,8,5,13)
> z <- cbind(x,y)
>
> Any idea how to convert z into the JSON format below?
>
> I want to get the following JSON output to put into a php file.
> [[0, 3], [4, 8], [8, 5], [9, 13]]
>
I have not tried RJSONIO, but with package rjson you could use:
> toJSON(as.data.frame(z))
[1] "{\"x\":[0,4,8,9],\"y\":[3,8,5,13]}"
> toJSON(as.data.frame(t(z)))
[1] "{\"V1\":[0,3],\"V2\":[4,8],\"V3\":[8,5],\"V4\":[9,13]}"
Dieter
--
View this message in context: http://r.789695.n4.nabble.com/toJSON-question-tp3083427p3083445.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list