我有几个类似于“PRISM_ppt_stable_4kmM2_--------_bil.bil”的文件,其中 ------ 是年和月,如 190112。文件日期范围从 189501 到 198012。在 R 中,在 Windows 上7机器,我想匹配从192001到193912的所有文件。我很确定我想要grepl()
,但我无法弄清楚在命令中引用序列的方法。我试过
my.files[grepl('PRISM.*/1920/.bil$',my.files)]
和
my.files[grepl('PRISM.*[1][9][2][0].',my.files)]
和其他变体,但只会收到错误消息。我知道 [0-9]{4} 将匹配任何四个数字序列,但这将匹配所有文件。