修改列表中特定名称的值

时间:2018-07-16 07:28:17

标签: r

假设我有一个包含多个名称的列表,例如百分比,敏感度等,如下所示。我想将特异性的值修改为1 - specificities,例如1.00000000, 0.9470085, 0.8666667 ...

如何在保留其余部分的同时进行修改?

> head(auc_rf)
$percent
[1] FALSE

$sensitivities
 [1] 1.0000000 0.9947735 0.9703833 0.9355401 0.9146341 0.8832753 0.8379791
 [8] 0.7944251 0.7630662 0.7299652 0.6829268 0.6445993 0.5993031 0.5679443
[15] 0.5348432 0.4965157 0.4721254 0.4320557 0.4024390 0.3780488 0.3362369
[22] 0.0000000

$specificities
 [1] 0.00000000 0.05299145 0.13333333 0.22393162 0.30427350 0.38461538
 [7] 0.46153846 0.54017094 0.60512821 0.68547009 0.75555556 0.80170940
[13] 0.84273504 0.87179487 0.91111111 0.93504274 0.95213675 0.96581197
[19] 0.97264957 0.97777778 0.98803419 1.00000000

$thresholds
 [1]  -Inf 0.025 0.075 0.125 0.175 0.225 0.275 0.325 0.375 0.425 0.475 0.525
[13] 0.575 0.625 0.675 0.725 0.775 0.825 0.875 0.925 0.975   Inf

$direction
[1] "<"

2 个答案:

答案 0 :(得分:1)

set.seed(1)
list1 <- list(runif(10,0,1), runif(sample(1:10, 10)))
names(list1) <- c("specifities", "var2")
list1$specifities

[1] 0.26550866 0.37212390 0.57285336 0.90820779 0.20168193 0.89838968 0.94467527 0.66079779 0.62911404 0.06178627    

list1$specifities <- 1 - list1$specifities
list1$specifities

[1] 0.73449134 0.62787610 0.42714664 0.09179221 0.79831807 0.10161032 0.05532473 0.33920221 0.37088596 0.93821373

答案 1 :(得分:0)

1- auc_rf[[2]]

OR

1- auc_rf[['specificities']]

更改名称:

names(auc_rf)[[2]] <- '1 - specificities'