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

2018-10-11 Thread Ek Esawi
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 tr

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

2018-10-10 Thread Rui Barradas
Hello, > month.names Erro: objeto 'month.names' não encontrado > month.name [1] "January" "February" "March" "April" "May" "June" [7] "July" "August""September" "October" "November" "December" Hope this helps, Rui Barradas Às 01:05 de 11/10/2018, William Dun

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

2018-10-10 Thread William Dunlap via R-help
You can paste the directory names, dir.names(files), back on, with file.path(), after you do the sorting. A better idiom is to use order() instead of sort() and usng order's output to subscript file.names. E.g., the following sorts by year and month number. > file.names <- c("C:/tmp/June_2018.PD

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

2018-10-10 Thread Duncan Murdoch
On 10/10/2018 7:23 PM, Ek Esawi wrote: Thank you Bill and RUI. I use month.name with sort and basename, as suggested by Bill. i got the sorted numerical values, then i use month.name to get proper ordered month names. The problem is that i have to paste to the names the extension PDF giving me th

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

2018-10-10 Thread Ek Esawi
Thank you Bill and RUI. I use month.name with sort and basename, as suggested by Bill. i got the sorted numerical values, then i use month.name to get proper ordered month names. The problem is that i have to paste to the names the extension PDF giving me the correct ordered file names, but then i

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

2018-10-09 Thread Ek Esawi
Thank you Jeff. It is an excellent idea and i might try it out if nothing works out. And i don't have 12 files on each sub directory; EK On Tue, Oct 9, 2018 at 11:30 AM Jeff Newmiller wrote: > > Instead of changing the order in which you read the files, perhaps your > analysis will work if you

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

2018-10-09 Thread William Dunlap via R-help
Use basename(filename) to remove the lead parts of the full path to the file. E.g., replace FNs <- sort(match(sub("\\.PDF", "", file.names), month.name)) with (the untested) FNs <- sort(match(sub("\\.PDF", "", basename(file.names)), month.name)) Bill Dunlap TIBCO Software wdunlap tibco.com

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

2018-10-09 Thread Rui Barradas
Hello, I would do something along the lines of # work in the directory where the files are located old_dir <- setwd(path) file.names <- list.files(pattern = "\\.PDF") [...] # When you are done reset your wd setwd(old_dir) Hope this helps, Rui Barradas Às 21:38 de 09/10/2018, Ek Esawi escre

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

2018-10-09 Thread Ek Esawi
Hi again, I worked with RUi's idea of using the match function with month.name. I got numerical values for months then i sorted and pasted the PDF file extension. It gave me the file order i wanted, but now statements 8,9,&10 don't work and i kept getting an error which is listed below. The dilemm

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

2018-10-09 Thread Jeff Newmiller
Instead of changing the order in which you read the files, perhaps your analysis will work if you sort the data after you read it in. This may require that you add the month names as a column in the data frames, or you may already have dates in the data that you could sort by. One idea: fnames

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

2018-10-09 Thread Jeff Newmiller
Instead of changing the order in which you read the files, perhaps your analysis will work if you sort the data after you read it in. This may require that you add the month names as a column in the data frames, or you may already have dates in the data that you could sort by. One idea: fnames

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

2018-10-09 Thread Rui Barradas
Hello, You can use the built in variable month.name to get the calendar order and match it with your file names. i <- match(sub("\\.PDF", "", file.names), month.name) file.names[i] #[1] "January.PDF" "February.PDF" "March.PDF" Hope this helps, Rui Barradas Às 14:44 de 09/10/2018, Ek Esa

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

2018-10-09 Thread PIKAL Petr
Cheers Petr > -Original Message- > From: R-help On Behalf Of Ek Esawi > Sent: Tuesday, October 9, 2018 3:44 PM > To: r-help@r-project.org > Subject: [R] Reorder file names read by list.files function > > Hi All-- > > I used base R list.file function to read files

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

2018-10-09 Thread Ek Esawi
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 Re