如何根据另一个向量的值(使用data.frame)对一个向量进行排序

时间:2016-04-14 08:49:40

标签: r

我有一个数据框'真实设置',我想根据矢量'顺序'中的值的顺序排序。

true_set <- data.frame(dose1=c(rep(1,5),rep(2,5),rep(3,5)), dose2=c(rep(1:5,3)),toxicity=c(0.05,0.1,0.15,0.3,0.45,0.1,0.15,0.3,0.45,0.55,0.15,0.3,0.45,0.55,0.6),efficacy=c(0.2,0.3,0.4,0.5,0.6,0.4,0.5,0.6,0.7,0.8,0.5,0.6,0.7,0.8,0.9),d=c(1:15))

orders<-matrix(nrow=3,ncol=15)
orders[1,]<-c(1,2,6,3,7,11,4,8,12,5,9,13,10,14,15)
orders[2,]<-c(1,6,2,3,7,11,12,8,4,5,9,13,14,10,15)
orders[3,]<-c(1,6,2,11,7,3,12,8,4,13,9,5,14,10,15)

预期结果将是:

首先订单[1,]:

   dose1 dose2 toxicity efficacy  d
1      1     1     0.05      0.2  1
2      1     2     0.10      0.3  2
3      2     1     0.10      0.4  6
4      1     3     0.15      0.4  3
5      2     2     0.15      0.5  7
6      3     1     0.15      0.5 11
7      1     4     0.30      0.5  4
8      2     3     0.30      0.6  8
9      3     2     0.30      0.6 12
10     1     5     0.45      0.6  5
11     2     4     0.45      0.7  9
12     3     3     0.45      0.7 13
13     2     5     0.55      0.8 10
14     3     4     0.55      0.8 14
15     3     5     0.60      0.9 15

第一个订单[2,]:如上所述

首先订单[3,]:如上所述

1 个答案:

答案 0 :(得分:0)

function toggleForums(catId) {
    var lctgCategory = "#cat_" + catId;

    if (jQuery(lctgCategory).hasClass('collapsed')) {
        jQuery.cookie("catStatus","collapsed",{expires: 365});
    } else {
        jQuery.cookie("catStatus","expanded",{expires: 365});
    }

    if (jQuery.cookie("catStatus") == "collapsed") {
        jQuery(lctgCategory).next().show();
        jQuery(lctgCategory).toggleClass('collapsed');
    } else {
        jQuery(lctgCategory).next().hide();
        jQuery(lctgCategory).toggleClass('collapsed');
    }
}