I have a list of file names:
filenames <- c( "data/climate/WorldClim/raw_1_year/raw/wc2.1_2.5m_tmin_1996-07.tif",
"data/climate/WorldClim/raw_1_year/raw/wc2.1_2.5m_tmin_1997-06.tif",
"data/climate/WorldClim/raw_1_year/raw/wc2.1_2.5m_tmin_1997-07.tif",
"data/climate/WorldClim/raw_1_year/raw/wc2.1_2.5m_tmin_1998-06.tif",
"data/climate/WorldClim/raw_1_year/raw/wc2.1_2.5m_tmin_1998-07.tif",
"data/climate/WorldClim/raw_1_year/raw/wc2.1_2.5m_tmin_1999-06.tif",
"data/climate/WorldClim/raw_1_year/raw/wc2.1_2.5m_tmin_1999-07.tif",
"data/climate/WorldClim/raw_1_year/raw/wc2.1_2.5m_tmin_2000-06.tif",
"data/climate/WorldClim/raw_1_year/raw/wc2.1_2.5m_tmin_2000-07.tif",
"data/climate/WorldClim/raw_1_year/raw/wc2.1_2.5m_tmin_2001-06.tif")
I want to select from 1998, 1999 and 2000.
I know how to do this for 1 year, but how can I select all 3 years?
str_detect(filelist, c("1998"))
[1] FALSE FALSE FALSE TRUE TRUE FALSE FALSE FALSE FALSE FALSE
str_detect(filenames, c("1998", "1999", "2000"))
[1] FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE TRUE FALSE
Warning message:
In stri_detect_regex(string, pattern, negate = negate, opts_regex = opts(pattern)) :
longer object length is not a multiple of shorter object length
The last line of code produces an incorrect result. The corrects result would produce TRUE for positions 5:9.