I have hourly data for January and February, and I need to filter the data by day of the week, so that I can separate the data into individual datasets for each day of the week.
Specifically, I need to create separate datasets for Sundays, Mondays, Tuesdays, Wednesdays, Thursdays, Fridays, and Saturdays, each containing the hourly data for that specific day of the week during the months of January and February.
You can use the wday function from the lubridate package to label each row with the day of the week. Typically, you would then use the group_by() function from dplyr to do calculations on each group but you can also make subsets based on the DayOfWeek column if you want to.
library(dplyr)
library(lubridate)
DF <- read.csv("~/R/Play/sample_data.csv")
DF <- DF |> mutate(DayofWeek = wday(date, label = TRUE))
head(DF)
#> date AE33_abs_880nm PAX_abs870 House_abs880nm DayofWeek
#> 1 2022-01-16 00:00 NaN NaN NaN Sun
#> 2 2022-01-16 01:00 NaN NaN NaN Sun
#> 3 2022-01-16 02:00 NaN NaN NaN Sun
#> 4 2022-01-16 03:00 NaN NaN NaN Sun
#> 5 2022-01-16 04:00 NaN NaN NaN Sun
#> 6 2022-01-16 05:00 NaN NaN NaN Sun