
上QQ阅读APP看书,第一时间看更新
How to do it...
Once the files are ready, load the jsonlite package and read the files as follows:
- Load the library:
> library(jsonlite)
- Load the JSON data from the files:
> dat.1 <- fromJSON("students.json")
> dat.2 <- fromJSON("student-courses.json")
- Load the JSON document from the web:
> url <- "http://finance.yahoo.com/webservice/v1/symbols/allcurrencies/quote?format=json"
> jsonDoc <- fromJSON(url)
- Extract the data into data frames:
> dat <- jsonDoc$list$resources$resource$fields
> dat.1 <- jsonDoc$list$resources$resource$fields
> dat.2 <- jsonDoc$list$resources$resource$fields
- Verify the results:
> dat[1:2,]
> dat.1[1:3,]
> dat.2[,c(1,2,4:5)]