'Creating seasonal subset

Having a little trouble with creating seasonal subsets in r.

The datetime is already in the POSIXct format so I didn't think it necessary to add the as.POSIXct() function. Also, the dataset is already organized by datetime.

This is what the current code looks like.

summer_subset <- subset(YTD_v5, YTD_v5$started_at >= '2021-06-21 00:00:00' & YTD_v5$ended_at <= '2021-09-21 23:59:59')

fall_subset <- subset(YTD_v5, YTD_v5$started_at >= '2021-09-22 00:00:00' & YTD_v5$ended_at <= '2021-12-20 23:59:59')

winter_subset <- subset(YTD_v5, (YTD_v5$started_at >= '2021-12-21 00:00:00' & YTD_v5$ended_at <= '2022-02-28 23:59:59') | (YTD_v5$started_at >= '2021-03-01 00:00:00' & YTD_v5$ended_at <= '2021-03-19 23:59:59'))

spring_subset <- subset(YTD_v5, YTD_v5$started_at >= '2021-03-20 00:00:00' & YTD_v5$ended_at <= '2021-06-20 23:59:59')

When I view the summer_subset, the rows start at 2021-06-21 04:00:00, not 00:00:00. The final entry is 2021-09-21 03:55:00, not 23:59:59.

In the YTD_v5 dataset, there are entries that contain start times at 00:00:00 and end times that end at 23:59:59.

Thanks for any insight in advanced.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source