After extensive searching on this issue, I still cannot find the solution. I have a simple data frame with 43 rows and 2 columns. My first column contains two dates. The first date is printed 19 times and the other 24 times. The second column is temperature. I want to find the max and min temperature by date, but my code keeps printing the entire data set's max and min.
Data:
Date <- c(rep(x = "2017-05-18", each= 19), rep(x = "2017-05-19", each= 24))
Temperature_F <- c(35, 35, 42, 49, 57, 63, 64, 67, 70, 71, 72, 71, 72, 70, 66, 61, 57, 54, 50, 49, 45, 44, 44, 42, 40, 39, 47, 53, 61, 67, 69,
72, 75, 76, 77, 76, 77, 75, 71, 66, 62, 58, 54)
NWS_temps1 <- data.frame(Date, Temperature_F)
Here is my dplyr code that keeps giving me the max and min for the entire temperature column when I think it should be giving me the max and min temperature by date.
NWS_temps1 <- tbl_df(NWS_temps1)
NWS_temps1 %>%
group_by(Date) %>%
summarise(Tmax = max(Temperature_F), Tmin= min(Temperature_F))
The output I get is:
Tmax Tmin
77 35
When I am hoping for:
Date Tmax Tmin
2017-05-18 72 35
2017-05-19 77 39
I don't understand why Date isn't be grouped as it should. I've attempted changing Date to a factor as it is here, character, date object, and even POSIXct, but my result is always the total data frame max and min.
Any help is much appreciated.
Thanks.