Import multiple yearly weather data , and combine it into a dataframe by loop

164 views Asked by At
library(weatherData)
for(i in 2003:2016) {

   c <- (getWeatherForYear(station_id = "BOS", year = i))

}

I am writing a loop to get the weather data from year 2003 to year 2016 from the function: getWeatherForYear and combine it into a dataframe

But after looping, dataframe only shows the weather data in year 2016 "not from year 2003 to 2016"

Could someone help me for fixing the loop that will produce a dataframe include the yearly weather data from year 2003 to 2016?

Thanks a lot

1

There are 1 answers

3
Iaroslav Domin On BEST ANSWER
df <- do.call(
    rbind,
    lapply(
        2003:2016, 
        function(i) getWeatherForYear(station_id = "BOS", year = i)
    )
)