作者Edster (Edster)
看板R_Language
标题[问题] 排序不定栏位的matrix
时间Wed Aug 26 18:03:50 2015
[问题类型]:
程式谘询(我想用R 做某件事情,但是我不知道要怎麽用R 写出来)
[软体熟悉度]:
开发者(有撰写R 的套件经验)
[问题叙述]:
假设一个 matrix 需要依照第一栏、第二栏、...、第N栏
类似这样, P就是要被排序的 matrix
if(N == 2) P=P[order(P[,1], P[,2], decreasing=T),]
if(N == 3) P=P[order(P[,1], P[,2], P[,3], decreasing=T),]
if(N == 4) P=P[order(P[,1], P[,2], P[,3], P[,4], decreasing=T),]
如果遇到不定栏位数量的,比如果遇到N=7,但一直写到N=7又不能解决N=8的问题
请问有什麽好方法呢?
[关键字]:
排序matrix
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 140.112.64.48
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/R_Language/M.1440583432.A.0B8.html