将json在线阅读到R时遗漏的数据

时间:2016-06-21 21:08:45

标签: json r

我尝试通过R:

中的以下代码将在线json数据读取到R.
library('jsonlite')

address<-'https://data.cityofchicago.org/resource/qnmj-8ku6.json'

sample<-fromJSON(address)

代码确实运行并以正确的格式生成结果。但只生产了1000个观测值,而原始城市门户数据库的观测量超过200,000个。我不确定要下载整个数据集要修复什么。请帮忙。

1 个答案:

答案 0 :(得分:0)

您使用错误的链接获取数据。您可以转到&#39;导出&#39;

来查看正确的链接
library(jsonlite)

address <- "https://data.cityofchicago.org/api/views/qnmj-8ku6/rows.json?accessType=DOWNLOAD"
sample <- fromJSON(address)

length(sample)
# [1]

length(sample[[2]])
# [1] 274228

虽然,您可能希望将其作为.csv使其更容易立即使用?

address <- "https://data.cityofchicago.org/api/views/qnmj-8ku6/rows.csv?accessType=DOWNLOAD"
sample_csv <- read.csv(address)

nrow(sample_csv) 
# [1] 274228

str(sample_csv) 
# 'data.frame': 274228 obs. of  22 variables:
#  $ ID                  : int  10512552 10517063 10517120 10518590 10518648 
# $ Case.Number         : Factor w/ 274219 levels "HA107183","HA156050",..
# $ Date                : Factor w/ 112977 levels "01/01/2014 01:00:00 AM",..
# $ Block               : Factor w/ 27499 levels "0000X E 100TH PL",..
# $ IUCR                : Factor w/ 331 levels "0110","0141",..
# $ Primary.Type        : Factor w/ 33 levels "ARSON","ASSAULT",..
# $ Description         : Factor w/ 310 levels "$500 AND UNDER",..
# ... etc