[英]data.frame to array of JSON arrays in R
I have a data frame in R with two columns, for example: 我在R中有一个有两列的数据框,例如:
df = data.frame(x=c(1, 2, 3, 4), y=c(5, 6, 7, 8))
I need to write an R script to convert this data.frame to a JSON array of arrays, like this: 我需要编写一个R脚本来将此data.frame转换为JSON数组数组,如下所示:
[[1, 5],[2, 6],[3, 7],[4, 8]]
How do I convert my data frame to a JSON array of rows in R? 如何将我的数据帧转换为R中的JSON数组?
We can use toJSON
from library(jsonlite)
我们可以从
library(jsonlite)
使用toJSON
library(jsonlite)
library(jsonlite)
toJSON(setNames(df, NULL))
#[[1,5],[2,6],[3,7],[4,8]]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.