我有一个这样的data.table:
Model Variable Coefficient standardized coefficient Model Variable Coefficient standardized coefficient Model
1: 0 Intercept 7.136994e+12 0.919481694 0.1 Intercept 2.201799e+12 0.918641093 0.2
2: 0 Comp_BK_Tot_Tot050500_i -1.177355e+13 -0.005086289 0.1 Comp_BK_Tot_Tot050500_i -3.632202e+12 -0.001569146 0.2
Variable Coefficient standardized coefficient Model Variable Coefficient standardized coefficient
1: Intercept 2.244410e+12 0.918648351 0.3 Intercept 2.258975e+12 0.918650832
2: Comp_BK_Tot_Tot050500_i -3.702495e+12 -0.001599514 0.3 Comp_BK_Tot_Tot050500_i -3.726523e+12 -0.001609894这是我的问题,我有一个变量保存为"0.3“作为new_num。如果列名"Model“包含= new_num,那么如何编写和表达式,然后选择该列和右边的下三个列?
例如,我希望在本例中的输出是:
Model Variable Coefficient standardized coefficient
0.3 Intercept 2.258975e+12 0.918650832
0.3 Comp_BK_Tot_Tot050500_i -3.726523e+12 -0.001609894 发布于 2018-05-22 15:35:43
我们可以先用索引('i1')对列进行子集,然后用'new_num‘的值指定'Model’
i1 <- match("Model", names(dt))
dt1 <- dt[, i1:(i1+3), with = FALSE][, Model := new_num][]https://stackoverflow.com/questions/50471529
复制相似问题