I have two tables, which I would like to join by date. If an instance falls within a color period, I would like that instance to receive said color as a variable (see joined):
instance <- read.table(header=TRUE, text="
ID UTC_DateTime Value
1 2022-06-15 15:00:00 8
2 2022-06-15 15:05:00 3
3 2022-06-15 15:10:00 2
4 2022-06-15 15:15:00 4
")
periods <- read.table(header=TRUE, text="
COLOR UTC_DateTime
Start_Green 2022-06-15 14:56:22
End_Green 2022-06-15 15:03:08
Start_Red 2022-06-15 15:03:11
End_Red 2022-06-15 15:58:48
")
joined <- read.table(header=TRUE, text="
ID UTC_DateTime Value Color
1 2022-06-15 15:00:00 8 Green
2 2022-06-15 15:05:00 3 Green
3 2022-06-15 15:10:00 2 Red
4 2022-06-15 15:15:00 4 Red
")
Also, if you could somehow incorporate a process which converts periods to periods_wide that would be great, see:
periods_wide <- read.table(header=TRUE, text="
COLOR UTC_DateTime_Start UTC_DateTime_End
Green 2022-06-15 14:56:22 2022-06-15 15:03:08
Red 2022-06-15 15:03:11 2022-06-15 15:58:48
")
Please be aware that there might be many more instances and also many more periods (of the same or other colors)