data = data.frame(v1 = c(2,"10+",3,4,5,6,7,8,9), v2 = c(15,30,12,59,44,24,67,19,35))
data$v1
[1] 2 10+ 3 4 5 6 7 8 9
Levels: 10+ 2 3 4 5 6 7 8 9
mixedorder(data$v1)
[1] 2 1 3 4 5 6 7 8 9
注意“10+”变为“1”。那是怎么回事?
答案 0 :(得分:1)
使用这样的正则表达式删除所有非数字字符:
data[order(as.numeric(gsub("[^[:digit:]]+", "", data$v1))),]
# v1 v2
#1 2 15
#3 3 12
#4 4 59
#5 5 44
#6 6 24
#7 7 67
#8 8 19
#9 9 35
#2 10+ 30