转-R排序
此次只用了order 错误,应该用rank
> nlxl1<-order(frame3$lxl1)
> nlxl2<-order(frame3$lxl2)
> nlxl3<-order(frame3$lxl3)
> nlxl4<-order(frame3$lxl4)
> nlxl5<-order(frame3$lxl5)
> nlxl6<-order(frame3$lxl6)
以下为原文链接:
http://blog.sina.com.cn/s/blog_6caea8bf0100spe9.html
在R中,和排序相关的函数主要有三个:sort(),rank(),order()。
> x<-c(97,93,85,74,32,100,99,67)
> sort(x)
[1]
> order(x)
[1] 5 8 4 3 2 1 7 6
> rank(x)
[1] 6 5 4 3 1 8 7 2
sort(x,index.return=TRUE)[[2]][sort(x,index.return=TRUE)[[1]]<90&sort(x,index.return=TRUE)[[1]]>50],后来发现sort(x,index.return=TRUE)[[2]]和order(x)的返回值是一样的,而sort(x,index.return=TRUE)[[1]]和sort(x)的返回值是相同的,因此语句可以简化为order(x)[sort(x)>50&sort(x)<90]。下面是相关的R代码:
> x
[1]
> sort(x,index.return=TRUE)[[2]][sort(x,index.return=TRUE)[[1]]<90&sort(x,index.return=TRUE)[[1]]>50]
[1] 8 4 3
> order(x)[sort(x)>50&sort(x)<90]
[1] 8 4 3
> sort(x,index.return=TRUE)
$x
[1]
$ix
[1] 5 8 4 3 2 1 7 6
> order(x)
[1] 5 8 4 3 2 1 7 6

浙公网安备 33010602011771号