I want to sort a vector of file names in R, just like how Windows sorts them when sorting by name (right-click --> sort by --> name).
Let's say I have four jpg files (I have more). Windows, when sorting by name, sorts them in a order as I've written below:
283_20200110_230606.jpg
500_20191203_032950.jpg
10889_20200114_165958.jpg
314368230_20200116_140854.jpg
R when using list.files()
, would sort them like this:
"10889_20200114_165958.jpg" "283_20200110_230606.jpg" "314368230_20200116_140854.jpg" "500_20191203_032950.jpg"
It seems in R character
, the number 1 always comes first, whereas Windows compares the numbers before the first underscore.
Is there a way to make them sorted in the same way? Either sort in R as Windows would, or sort in Windows as R does?
EDIT:
data for testing:
v1 <- c("10889_20200114_165958.jpg", "283_20200110_230606.jpg", "314368230_20200116_140854.jpg", "500_20191203_032950.jpg")