Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 将名称列为JSON对象名称_R_Dplyr_Jsonlite - Fatal编程技术网

R 将名称列为JSON对象名称

R 将名称列为JSON对象名称,r,dplyr,jsonlite,R,Dplyr,Jsonlite,我在R中面临JSON对象命名的问题 df = list(`Choose to and fro flights` = data.frame(sec =c('15:31:36' ,'15:31:37'),label=c("Choose to and fro flights","Choose to and fro flights"),responseCode = c( 200, 200), Counting=c(9,1)), `Details` = data.frame(sec = c("15:

我在R中面临JSON对象命名的问题

 df = list(`Choose to and fro flights` =  data.frame(sec =c('15:31:36' ,'15:31:37'),label=c("Choose to and fro flights","Choose to and fro flights"),responseCode = c( 200, 200), Counting=c(9,1)),
 `Details` = data.frame(sec = c("15:31:37" ,"15:31:37","15:31:38","15:31:39"),label = c("Details","Details","Details","Details"),responseCode = c("200","Non HTTP response code: org.apache.http.NoHttpResponseException","200","200"), Counting=c(2,2,5,1)))
我希望标签名与这里的JSON对象名相同 我正在尝试以下代码,但它没有给出正确的答案

toJSON(list(ResponseCode=lapply(seq_along(df), function(i) {    list(R_C_seconds=df[[i]]$sec,R_C_labels=df[[i]]$label,R_C_responseCode=df[[i]]$responseCode,R_C_Count=df[[i]]$Counting)})))
是我的输出:

我想用标签名替换01

lapply()
如果原始参数有名称,则在结果上设置名称。因此,您需要构建这样一个命名向量,而不是
seq_-along(df)

idx <- seq_along(df)
names(idx) <- names(df)
lappy()
如果原始参数有名称,则在结果上设置名称。因此,您需要构建这样一个命名向量,而不是
seq_-along(df)

idx <- seq_along(df)
names(idx) <- names(df)