我试图找到一种更快的方法来产生下面的输出
RV_1 RV_2 RV_3 RV_4 RV_5 rank.valueA rank.valueB rank.valueC rank.valueD rank.valueE
0.01 1.05 2632 0.96 2.8 9.35 10 12 11 8 6
0.01 1.05 2632 0.96 2.8 9.35 10 12 11 8 6
0.01 1.05 2632 0.96 2.8 9.35 10 12 11 8 6
0.01 1.05 2632 0.96 2.8 9.35 10 12 11 8 6
0.01 1.05 2632 0.96 2.8 9.35 10 12 11 8 6
0.01 1.05 2632 0.96 2.8 9.35 10 12 11 8 6
下面是示例参考表和输入表(标记为表)以及使用的代码。这需要很长时间,我正在尝试找到一种更快的方法。任何帮助和指导,将不胜感激。
表:
RV_1 RV_2 RV_3 RV_4 RV_5
0.01 1.052632 0.96 2.8 9.35
0.01 1.052632 0.96 2.8 9.35
0.01 1.052632 0.96 2.8 9.35
0.01 1.052632 0.96 2.8 9.35
0.01 1.052632 0.96 2.8 9.35
0.01 1.052632 0.96 2.8 9.35
参考表:
RV_1 RV_2 RV_3 RV_4 RV_5
3.000000e-01 8.7e+00 1.340000e+01 1.70e+01 0.00e+00
2.384615e-01 7.4e+00 1.124615e+01 1.31e+01 2.90e+00
2.076923e-01 6.7e+00 1.016923e+01 1.12e+01 4.40e+00
1.769231e-01 6.0e+00 9.092308e+00 9.30e+00 5.90e+00
1.461538e-01 5.4e+00 8.015385e+00 7.30e+00 7.30e+00
1.153846e-01 4.7e+00 6.938462e+00 5.40e+00 8.80e+00
8.461539e-02 4.0e+00 5.861538e+00 3.50e+00 1.03e+01
5.384615e-02 3.4e+00 4.784615e+00 1.60e+00 1.18e+01
2.307692e-02 2.7e+00 3.707692e+00 -4.00e-01 1.32e+01
-7.692308e-03 2.0e+00 2.630769e+00 -2.30e+00 1.47e+01
-3.846154e-02 1.4e+00 1.553846e+00 -4.20e+00 1.62e+01
-6.923077e-02 7.0e-01 4.769231e-01 -6.20e+00 1.76e+01
-1.000000e-01 0.0e+00 -6.000000e-01 -8.10e+00 1.91e+01
-1.000000e+09 -1.0e+09 -1.000000e+09 -1.00e+09 1.00e+08
代码:
for (i in seq(nrow(table))){
table$rank.valueA[i]=min(which(reference.table[,values[1]]<=table[i,values[1]]))
table$rank.valueB[i]=min(which(reference.table[,values[2]]<=table[i,values[2]]))
table$rank.valueC[i]=max(which(reference.table[,values[3]]>=table[i,values[3]]))
table$rank.valueD[i]=min(which(reference.table[,values[4]]<=table[i,values[4]]))
table$rank.valueE[i]=max(which(reference.table[,values[5]]<=table[i,values[5]]))})