How to order a character vector in ascend form in R

前端 未结 4 1920
感动是毒
感动是毒 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

    There are a few ways to do this. Here's another one:

    b <- c("A1","A10","A11","A12","A13","A14","A15","A2","A3","A4","A5","A6","A7")
    b[order(nchar(b), b)]
    # [1] "A1"  "A2"  "A3"  "A4"  "A5"  "A6"  "A7"  "A10" "A11" "A12" "A13" "A14" "A15"
    

提交回复
热议问题