Say I have a file that I would like to load in R - let's call it file.csv
. It's fairly easy to load this into R.
Unfortunately in my case multiple versions of this file exist and each file has a date appended to it... so that what I really have in my directory is a list of files such as:
file - 02-19-2013.csv
file - 02-18-2013.csv
file - 02-17-2013.csv
... and so on
I am wondering how I can go about loading the file with the most recent date in R?
You need to get the date out of the file name string (try substr
).
And then convert it to a date object using any of the numerous date parsing functions.
And then order by the order of those date objects.
Or if you are lucky you might just discover that your date format in your file names sort in the right way just by using sort
on your vector of filenames...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With