# Libraries
library(dplyr)
# First 5 observations in each month
m4_daily %>%
group_by(id) %>%
slice_period(1:5, .period = "1 month")
# Last observation in each month
m4_daily %>%
group_by(id) %>%
slice_period(n(), .period = "1 month")
Run the code above in your browser using DataLab