订单列,整数用" - "在R

时间:2018-02-25 11:53:21

标签: r

我想订购一个包含如下字符的列:

K3SG1-105-1051-1

但是,使用编配功能将导致:

K3SG1-105-1051-1

K3SG1-105-1051-10

K3SG1-105-1051-100

K3SG1-105-1051-1000

而不是我想要的:

K3SG1-105-1051-1

K3SG1-105-1051-2

K3SG1-105-1051-3

K3SG1-105-1051-4

提前致谢。

1 个答案:

答案 0 :(得分:0)

可以使用python gbus_count.py < A-small-attempt3.in > output.out tidyr::separate

dplyr

说明:将列# Sample data df <- data.frame(id = paste0("K3SG1-105-1051-", seq(1:10))); # Using separate df %>% separate(id, into = paste0("id", 1:4), sep = "-", remove = FALSE) %>% arrange(as.numeric(id4)) %>% select(id); # id #1 K3SG1-105-1051-1 #2 K3SG1-105-1051-2 #3 K3SG1-105-1051-3 #4 K3SG1-105-1051-4 #5 K3SG1-105-1051-5 #6 K3SG1-105-1051-6 #7 K3SG1-105-1051-7 #8 K3SG1-105-1051-8 #9 K3SG1-105-1051-9 #10 K3SG1-105-1051-10 拆分为四个单独的列,基于id作为分隔符; "-"行基于第四列条目,转换为arrange以确保正确排序。