工作生活

R语言order排序

2019-07-03  本文已影响0人  ChrisNing
#创建向量
name <- c("a","b","c","d","e","f","g","h","i","j")
number1 <- c(2,4,4,6,8,10,12,14,16,18)
number2 <- c(10.5,9.5,8.5,7.5,6.5,5.5,4.5,3.5,2.5,1.5)

#组成dataframe,注意此处需要使用data.frame函数,用cbind会造成向量变为character
data <- data.frame(name,number1,number2)
class(data)

#查看number1列正序秩次
order(data$number1,decreasing = F)

#查看number1列倒序秩次
order(data$number1,decreasing = T)
data

#以number1为第一顺序,number为第二顺序,两者皆正序排列
data[order(data$number1,data$number2,decreasing = F),]

上一篇下一篇

猜你喜欢

热点阅读