I have some files that I am listing using:
dir <- list.files("/data/2014", "*.img$", full.names = TRUE)
example of the file listed in dir
:
"/data/2014/file300.data.20141231.MC.9.vgf.img"
so all files have the same name but change with date 20141231
and hour 9
R lists the files according to the date and that is fine but it misses up the hour lie this:
10 1 11 12.....20 2 21 22....24 3 4....
which should be 0 1 2 3 4 5 6 .....10 11 ..... 20 21 ....24
I tried mixedsort
from gtools
with no success.
xx <- c('file300.data.20141231.MC.10.vgf.img', 'file300.data.20141231.MC.24.vgf.img',
'file300.data.20141231.MC.9.vgf.img', 'file300.data.20141231.MC.1.vgf.img',
'file300.data.20141231.MC.2.vgf.img')
xx
# [1] "file300.data.20141231.MC.10.vgf.img"
# [2] "file300.data.20141231.MC.24.vgf.img"
# [3] "file300.data.20141231.MC.9.vgf.img"
# [4] "file300.data.20141231.MC.1.vgf.img"
# [5] "file300.data.20141231.MC.2.vgf.img"
now test mixedsort()
dir1 <- mixedsort(xx)
dir1
# [1] "file300.data.20141231.MC.10.vgf.img"
# [2] "file300.data.20141231.MC.1.vgf.img"
# [3] "file300.data.20141231.MC.2.vgf.img"
# [4] "file300.data.20141231.MC.24.vgf.img"
# [5] "file300.data.20141231.MC.9.vgf.img"
What I want is like this:
# [1] "file300.data.20141231.MC.1.vgf.img"
# [2] "file300.data.20141231.MC.2.vgf.img"
# [3] "file300.data.20141231.MC.9.vgf.img"
# [4] "file300.data.20141231.MC.10.vgf.img"
# [5] "file300.data.20141231.MC.24.vgf.img"