Hi,
Just posting this as an additional method as you stated you were using a time series, and I personally prefer to extract around dates/datetimes
You can use the dates/times in a filter as below:
library(tidyverse)
library(lubridate)
## example dataframe
df <- tibble(
date = seq(ymd('2021-01-01'), ymd('2021-12-31'), by = 1), ## ymd() sets the format of your timesereis
var_1 = sample(1:100, 365, replace=TRUE),
var_2 = sample(50:75, 365, replace=TRUE)
)
## extract using dates
df_extract <- df %>%
filter(
between(date, ymd('2021-05-01'), ymd('2021-05-31')) ## ensure the filter format matches the format in the df
)
If your timeseries is a higher resolution, just change the formatting of the times to ymd_hms() (this goes down to seconds). Run ?lubridate for more information on that.
Hope this is useful.