将数据从 JSON 文件导入 R [英] Importing data from a JSON file into R

查看:63
本文介绍了将数据从 JSON 文件导入 R的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法将数据从 JSON 文件导入 R?更具体地说,该文件是一个包含字符串字段、对象和数组的 JSON 对象数组.RJSON 包不是很清楚如何处理这个 http://cran.r-project.org/web/packages/rjson/rjson.pdf.

Is there a way to import data from a JSON file into R? More specifically, the file is an array of JSON objects with string fields, objects, and arrays. The RJSON Package isn't very clear on how to deal with this http://cran.r-project.org/web/packages/rjson/rjson.pdf.

推荐答案

首先安装 rjson 包:

First install the rjson package:

install.packages("rjson")

那么:

library("rjson")
json_file <- "http://api.worldbank.org/country?per_page=10&region=OED&lendingtype=LNX&format=json"
json_data <- fromJSON(paste(readLines(json_file), collapse=""))

更新:自 0.2.1 版

json_data <- fromJSON(file=json_file)

这篇关于将数据从 JSON 文件导入 R的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆