Group data into 4 seasons

Hi, I would like to group my hourly data in 2018 into 4 seasons and I have tried to do it but it is not successful, so do you guys know how to do it?

TMData$DATE <- case_when(

  • between(TMData$DATE, as.Date("2018-12-31"), as.Date("2018-02-28")) ~ "Winter",
  • between(TMData$DATE, as.Date("2018-03-01"), as.Date("2018-05-31")) ~ "Spring",
  • between(TMData$DATE, as.Date("2018-06-01"), as.Date("2018-08-31")) ~ "Summer",
  • between(TMData$DATE, as.Date("2018-09-01"), as.Date("2018-11-30")) ~ "Autumn",
  • TRUE ~ "Fall"
  • )
    Error in case_when():
    ! Failed to evaluate the left-hand side of formula 1.
    Caused by error in between():
    ! Can't combine x and left .
    Run rlang::last_trace() to see where the error occurred.

Hi,

I think between doesn’t handle dates, but numeric values:

You could try Lubridate

Then you can make an interval and use %within%

Also, I would check your Winter dates.

between() does work with dates, e.g.

dplyr::between(as.Date("2024-02-15"), as.Date("2024-02-14"), as.Date("2024-02-16"))

I suspect that TMData$DATE may not be defined as a date, but it's impossible to know without a reproducible example:

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.