[R] toJSON question
Duncan Temple Lang
duncan at wald.ucdavis.edu
Sat Dec 11 17:19:44 CET 2010
On 12/11/10 8:00 AM, 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]]
The toJSON() function is the basic mechanism.
In this case, z has names on the columns.
colnames(z) = NULL
Then toJSON(z) gives you want you want.
If you want to remove the new line (\n) characters,
gsub("\\\n", "", toJSON(z))
> Thank you.
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help