在R中将嵌套列表转换为数据帧的问题[观察结果被视为数据帧中的列表]

时间:2019-02-27 18:48:39

标签: r json dataframe purrr

我用了几百个json文件来创建最终数据dp

temp <- list.files("/mypath", pattern="*.json", full.names=TRUE) # this should give you a character vector, with each file name represented by an entry
final_data <- purrr::map_df(temp, function(x) { purrr::map(jsonlite::fromJSON(x), function(y) ifelse(is.null(y), NA, y)) })

我试图将final_data_1转换为R数据帧,但是它没有像列名,观测值计数,它们的类型等正常数据帧那样显示值。它将观测值/行视为列表!

final_data_1<-as.data.frame(final_data)
str(final_data_1)

这就是我得到的,并在数据框中的列表中创建观察结果

str(final_data_2)
'data.frame':   2 obs. of  4 variables:
$ bwithbug          :List of 2
..$ : chr "true"
..$ : chr "true"
$ caseid            :List of 2
..$ : chr "683748427"
..$ : chr "683791530"
$ casestate         :List of 2
..$ : chr "Closed"
..$ : chr "Closed"
$ csone             :List of 2
..$ : chr "1119006046"
..$ : chr "1119064677"

我面临的问题是否有任何解决方法

0 个答案:

没有答案