[R] Reorder file names read by list.files function

Ek Esawi e@@w|ek @end|ng |rom gm@||@com
Thu Oct 11 13:32:43 CEST 2018

Thank you all. Bill's original idea worked well. I did not realize
that i had to paste the full dir name to the correctly ordered file.
Once that was done it did work well. I will try REUI's idea  and i
think Jeff's idea of rearranging the output after extracting the
tables might work and i will try it and see.

Thank you all.

On Tue, Oct 9, 2018 at 9:44 AM Ek Esawi <esawiek using gmail.com> wrote:
> Hi All--
> I used base R list.file function to read files from a directory. The
> file names are months (April, August, etc). That's the system reads
> them in alphabetical order., but i want to reordered them in calendar
> order (January, February, ...December).. I thought i might be able to
> do it via RegEx or possibly gtools package, I am wondering if there is
> an easier way.
> Thanks--EK
> Example
> path = "C:/Users/name/Downloads/MyFiles"
> file.names <- dir(path, pattern =".PDF")
> Example output
> Output:
> "February.PDF"  "January.PDF" "March.PDF"
> Desired output
> "January.PDF"  "February.PDF" "March.PDF"

More information about the R-help mailing list