将Json解析为R中的数据帧
我有以下格式的json数据将Json解析为R中的数据帧,json,r,dataframe,Json,R,Dataframe,我有以下格式的json数据 {"abc": "37512", "def": "93145", "ghi": "14160", "jkl": "510842"} 我需要在R会话中将其作为数据帧加载 col1 col2 abc 37512 def 93145 ghi 14160 jkl 510842 我尝试使用rsjon解析json。这是我的密码: library("rjson") json_file <- 'finaldata.json' data <- fromJSON(fil
{"abc": "37512", "def": "93145", "ghi": "14160", "jkl": "510842"}
我需要在R会话中将其作为数据帧加载
col1 col2
abc 37512
def 93145
ghi 14160
jkl 510842
我尝试使用rsjon解析json。这是我的密码:
library("rjson")
json_file <- 'finaldata.json'
data <- fromJSON(file=json_file)
data
$abc
[1] "37512"
$def
[1] "93145"
$ghi
[1] "14160"
$jkl
[1] "510842"
库(“rjson”)
json_文件您可以使用stack
frombase R
stack(data)
# values ind
#1 37512 abc
#2 93145 def
#3 14160 ghi
#4 510842 jkl
或从重塑2
library(reshape2)
melt(data)
并更改列名
setNames(melt(data)[,2:1], paste0('col', 1:2))
# col1 col2
#1 abc 37512
#2 def 93145
#3 ghi 14160
#4 jkl 510842