Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/77.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中的数字向量?_R_Json_Import_Numeric - Fatal编程技术网

如何将具有逗号分隔值的因子转换为R中的数字向量?

如何将具有逗号分隔值的因子转换为R中的数字向量?,r,json,import,numeric,R,Json,Import,Numeric,我从json文件导入数据,需要一些元素作为数值 json: [ { "a": 52, "b": 2020, "c": 14, "d": "1,2,3,4,5,6,7,8,9", "e": "4,1,2,3,1,0,0,0,0", "f": "TRUE" } ]

我从json文件导入数据,需要一些元素作为数值

json:

[
  {
    "a": 52,
    "b": 2020,
    "c": 14,
    "d": "1,2,3,4,5,6,7,8,9",
    "e": "4,1,2,3,1,0,0,0,0",
    "f": "TRUE"
  }
]
导入的代码:

json_file <- fromJSON(file = "file")

json_file <- lapply(json_file, function(x) {
  x[sapply(x, is.null)] <- NA
  unlist(x)
})

json_file <-as.data.frame(do.call("rbind", json_file))
致意
tholori

help(“strsplit”)
您可以尝试
as.numeric(as.character(json\u文件$d))
help(“strsplit”)
您可以尝试
as.numeric(as.character(json\u文件$d))
d_numeric <- as.numeric(json_file$d)
str(json_file$d)
 Factor w/ 1 level "1,2,3,4,5,6,7,8,9": 1
 - attr(*, "names")= chr "Woche"