Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading files with the most recent date in R [duplicate]

Tags:

r

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?

like image 871
Berk U. Avatar asked Oct 22 '22 16:10

Berk U.


1 Answers

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...

like image 119
Spacedman Avatar answered Oct 24 '22 11:10

Spacedman