It's a good question.
The simplest way to do it is to look up the label for the period from your message column in timestamps, using the same syntax with $ for the column name and [ ] to specify the item number in the column. My example would be:
library(dplyr)
# random sample data for videos
timestamps <- tibble(
timestamp = c(0, sort(round(sample(50000, 2)/1000, 1)), 50),
message = c(paste0("period", 1:(length(timestamp)-1)), "end")
)
# random timings for the events to be classified
session_time <- sort(round(sample(50000, 8)/1000, 3))
# use dplyr::case_when to categorise and label times
tibble::as_tibble_col(session_time, column_name = "session_time") %>%
mutate(period = case_when(
session_time > timestamps$timestamp[3] ~ timestamps$message[3],
session_time > timestamps$timestamp[2] ~ timestamps$message[2],
session_time > timestamps$timestamp[1] ~ timestamps$message[1]
)
)
#> # A tibble: 8 x 2
#> session_time period
#> <dbl> <chr>
#> 1 2.14 period1
#> 2 6.28 period1
#> 3 8.84 period1
#> 4 21.8 period2
#> 5 22.5 period2
#> 6 25.4 period2
#> 7 32.2 period2
#> 8 48.6 period3
Created on 2020-09-27 by the reprex package (v0.3.0)
I haven't been able to work out a way of getting the case-when statements (session_time > ...) to construct themselves out automatically! I feel like there should be. But for now I have just written them in by hand. If you had many different videos, it could become a very long case_when statement!