[R] JSON data in data frame

Rob Baer rwbaer at gmail.com
Sat Jan 14 19:27:40 CET 2017


Try this:

# get weather data
library(jsonlite)
dat<- 
fromJSON('http://api.openweathermap.org/data/2.5/group?id=524901,703448,2643743&units=metric&appid=ec0313a918fa729d4372555ada5fb1f8')
tab <- dat$list

#look at what we get
class(tab)
names(tab)
ncol(tab)
nrow(tab)
tab[,c("clouds","wind","name")]
tab$wind$speed
tab$wind[,c("speed", "deg")]

Here's my output.  Is this what you get/want?  If not, what do you hope 
for?  As an aside are you working in standard R if you get an error?

 > # get weather data
 > library(jsonlite)
 > dat<- 
fromJSON('http://api.openweathermap.org/data/2.5/group?id=524901,703448,2643743&units=metric&appid=ec0313a918fa729d4372555ada5fb1f8')
 > tab <- dat$list
 >
 > #look at what we get
 > class(tab)
[1] "data.frame"
 > names(tab)
  [1] "coord"      "sys"        "weather"    "main"
  [5] "visibility" "wind"       "clouds"     "dt"
  [9] "id"         "name"
 > ncol(tab)
[1] 10
 > nrow(tab)
[1] 3
 > tab[,c("clouds","wind","name")]
   all wind.speed wind.deg wind.var_beg wind.var_end   name
1  90        6.0      150          120          190 Moscow
2  90        4.0      190           90          230   Kiev
3   0        3.6      280           NA           NA London
 > tab$wind$speed
[1] 6.0 4.0 3.6
 > tab$wind[,c("speed", "deg")]
   speed deg
1   6.0 150
2   4.0 190
3   3.6 280
 >






4/2017 9:44 AM, Archit Soni wrote:
>
> library(jsonlite)
> dat<- 
> fromJSON('http://api.openweathermap.org/data/2.5/group?id=524901,703448,2643743&units=metric&appid=ec0313a918fa729d4372555ada5fb1f8 
> <http://api.openweathermap.org/data/2.5/group?id=524901,703448,2643743&units=metric&appid=ec0313a918fa729d4372555ada5fb1f8>')
> tab <- dat$list


	[[alternative HTML version deleted]]



More information about the R-help mailing list