Search code examples
rweatherdata

R weatherData Detroit station error


I keep getting errors in my attempt to pull weather data for Detroit airport. I am able to manually go to wunderground.com to get the historical hourly data, so it does exist there for Detroit location. But R package keeps sending me errors. I used "KDTW" for the airport code but it did not work. I tried "72537" for the station ID, which I got by using getStationCode("Detroit). I will appreciate any help with getting hour historical data for any close to Detroit station for the time interval January 1, 2017 through March 28, 2017.

Here is what I tried:

 install.packages("weatherData")  
 library ('weatherData')  

getStationCode("Detroit")  
checkDataAvailabilityForDateRange(station_type ="KARB", start_date="2017-01-01", end_date="2017-03-28")  
checkDataAvailabilityForDateRange(station_id ="KDTW", start_date="2017-01-01", end_date="2017-03-28")   

Thank you!


Solution

  • I was able to get the weather data for KDTW. temp <- getWeatherForDate(station_id = "KDTW", start_date = "2017-01-01", end_date="2017-01-10")

    Here is my output for the date range

    structure(c("Min.   :2017-01-01 00:00:00  ", "1st Qu.:2017-01-03 06:00:00  ", 
    "Median :2017-01-05 12:00:00  ", "Mean   :2017-01-05 12:00:00  ", 
    "3rd Qu.:2017-01-07 18:00:00  ", "Max.   :2017-01-10 00:00:00  ", 
    "Min.   :17.0  ", "1st Qu.:18.5  ", "Median :34.5  ", "Mean   :31.9  ", 
    "3rd Qu.:42.5  ", "Max.   :49.0  ", "Min.   :11.00  ", "1st Qu.:13.75  ", 
    "Median :26.50  ", "Mean   :25.20  ", "3rd Qu.:34.25  ", "Max.   :41.00  ", 
    "Min.   : 5.0  ", "1st Qu.: 9.0  ", "Median :17.5  ", "Mean   :18.2  ", 
    "3rd Qu.:26.0  ", "Max.   :37.0  "), .Dim = c(6L, 4L), .Dimnames = list(
        c("", "", "", "", "", ""), c("     Date", "Max_TemperatureF", 
        "Mean_TemperatureF", "Min_TemperatureF")), class = "table")
    

    I just got temperature data, but if you'd like, you can also get other information (like humidity, cloud cover, etc) by changing the opt_all_columns flag to TRUE.

    Hope that Helps!

    Edit: Looking at your code you have station_type ="KARB" Did you mean that to be station_id?