How to order a character vector in ascend form in R

前端 未结 4 1926
感动是毒
感动是毒 2021-01-16 11:35

Hi everybody I am trying to solve a problem in R. I want to read a lot of files allocated in multiples sub folders in a main folder. Then I used list.files() t

4条回答
  •  花落未央
    2021-01-16 12:09

    If this is the exact data that you have, you can sort it the way you want like this:

    > b[order(as.integer(substr(b,2,3)))]
     [1] "A1"  "A2"  "A3"  "A4"  "A5"  "A6"  "A7"  "A8"  "A9"  "A10" "A11" "A12"
    [13] "A13" "A14" "A15"
    

    If the actual data is more complicated, you might have to do a little more string manipulation, but this is the general idea.

提交回复
热议问题