如何在R中将数据帧转换为json格式

如何在R中将数据帧转换为json格式,r,R,我有这样一个数据框: dput(head(y,20)) structure(list(DATETIME = structure(c(1369540800, 1369541700, 1369542600, 1369543500, 1369544400, 1369545300, 1369546200, 1369547100, 1369548000, 1369548900, 1369549800, 1369550700, 1369551600, 1369552500, 1369553400, 1

我有这样一个数据框:

dput(head(y,20))
structure(list(DATETIME = structure(c(1369540800, 1369541700, 
1369542600, 1369543500, 1369544400, 1369545300, 1369546200, 1369547100, 
1369548000, 1369548900, 1369549800, 1369550700, 1369551600, 1369552500, 
1369553400, 1369554300, 1369555200, 1369556100, 1369557000, 1369557900
), class = c("POSIXct", "POSIXt"), tzone = ""), CPU = c(14.84, 
13.6333333333333, 14.7666666666667, 13.5333333333333, 17.8666666666667, 
15.9333333333333, 14.2333333333333, 13.3, 10.8333333333333, 9.76666666666667, 
8.93333333333333, 9.43333333333333, 10.2, 6.63333333333333, 13, 
14.3, 15.3666666666667, 16.6666666666667, 17.8666666666667, 14.7
)), .Names = c("DATETIME", "CPU"), row.names = c(NA, 20L), class = "data.frame")
我想将此数据帧转换为json格式,如下所示:

library(RJSONIO)
data<-toJSON(y)
cat(data, file="data.json"

这在Windows R 3.0.1上适用。@Thomas,你在json文件中看到CPU头信息了吗(我得到了CPU数据,但没有得到头)我用
rjson
尝试了这一点,只通过了DATETIME。然后我试了一下,一切都通过了:<代码>{“日期时间:”<代码>{“日期时间:”<代码>{“日期时间::[1.3695e+09,1.3695e+9,1.3695e+9,1.3695e+9,1.3695e+9,1.3695e+9,1.3695e+9,1.36955.3695e+9,1.36955+9,1.3695e+9,1.3695e+9,1.3695e+9,1.3695e+9,1.36955+9,1.36959,1.3695e+9,1.3695e+9,1.3695e+9,1.3695e+9,1.9,1.3695e+9,1.369,1.3695e+9,1+9,1.369,1.369,1.3695e+9,1“CPU”:[14.84,13.633,14.767,13.533,17.867,15.933,14.233,13.3,10.833,9.7667,8.9333,9.4333,10.2,6.6333,13,14.3,15.367,16.667,17.867,14.7]}@Thomas,你用了什么命令?@Thomas,我知道了,谢谢。
[{"DATETIME":[1369540800,1369541700,1369542600,1369543500,1369544400