我正在尝试将多个 json 文件读入工作目录以进一步转换为数据集。我在 json 目录中有文件 text1、text2、text3。这是我写的代码:
setwd("Users/Desktop/json")
temp = list.files(pattern="text*.")
myfiles = lapply(temp, read.delim)
library("rjson")
json_file <- "myfiles"
library(jsonlite)
out <- jsonlite::fromJSON(json_file)
out[vapply(out, is.null, logical(1))] <- "none"
data.frame(out, stringsAsFactors = FALSE)[,1:5]
View(out)
我有大约 200 个文件,所以我想知道是否有办法导入 json 文件。
Thanks
我认为在使用 Twitter 数据时我也遇到过类似的问题。我有一个目录,其中包含每个用户名的单独文件,我想将它们作为一个组导入/分析。这对我有用:
library(rjson)
filenames <- list.files("Users/Desktop/json", pattern="*.json", full.names=TRUE) # this should give you a character vector, with each file name represented by an entry
myJSON <- lapply(filenames, function(x) fromJSON(file=x)) # a list in which each element is one of your original JSON files
如果这不起作用,那么我需要更多信息来理解您的问题。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)