我有以下data.frame“测试”:
Cytoband
9p
1q
10p
22p
2q我想要得到:
Cytoband
1q
2q
9p
10p
22p这是我的代码:
indices <- order(test$Cytoband, decreasing = FALSE)
test <- test[indices,]但我明白:
10p
1q
22p
2q
9p有简单的修改吗?谢谢!
发布于 2015-06-26 19:54:58
您也可以尝试使用mixedsort或mixedorder
library(gtools)
out = data.frame(Cytoband = mixedsort(dat$Cytoband))
#> out
# Cytoband
#1 1q
#2 2q
#3 9p
#4 10p
#5 22p使用mixedorder
dat[mixedorder(as.character(dat$Cytoband)),]发布于 2015-06-26 19:42:40
x = c("9p","1q","10p","22p","2q")
y = x[order(as.numeric(gsub("\\D","",x)))]
y
[1] "1q" "2q" "9p" "10p" "22p"发布于 2015-06-26 19:44:47
test[order(as.numeric(gsub('(\\d+)[a-z]*', '\\1', test[,1]))),, drop=F]
Cytoband
2 1q
5 2q
1 9p
3 10p
4 22phttps://stackoverflow.com/questions/31080873
复制相似问题