Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Narrow down files which names include date to specific months in r

I have thousands of .tif files which contain daily temperature data. The file names include the date in a format like this tminYYYYMMDD.tif, here is a sample:

tmin19810707.tif
tmin19810508.tif
tmin19810314.tif
tmin19810227.tif

I only need the data from June (06), July (07) and August (08) form all those years. How can I select and use for further processing only files that are from those months?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

We can use substr for a base R solution:

x <- c("tmin19810707.tif", "tmin19810508.tif", "tmin19810314.tif",
       "tmin19810227.tif")
output <- x[substr(x, 9, 10) %in% c("06", "07", "08")]
output

[1] "tmin19810707.tif"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading