gpt4 book ai didi

显式删除列表的元素

转载 作者:行者123 更新时间:2023-12-04 02:50:25 25 4
gpt4 key购买 nike

我有这个 list :

myList <- list(rnorm(10), rnorm(10), rnorm(10))

names(myList) <- c("one", "two", "three")

$one
[1] -0.07587506 -0.09997924 -0.41846732 1.41542651 -0.58678093 0.56909465 -1.11074541
[8] 1.94663786 0.46381799 -0.11458166

$two
[1] 0.98883679 -0.06305794 -0.78961229 1.21091484 0.19636700 0.27458057 0.12374154
[8] 0.83782946 -0.79627870 0.97675486

$three
[1] 0.67033455 -0.80243815 0.08716750 -2.90455146 -0.02433571 -0.93062428 -0.16886116
[8] -0.60927976 -1.77758270 -1.05033148

我要删除 twothree从列表中,我想使用“二”和“三”来指代这些元素。我试过了:
myList <- myList[[-c("two", "three")]]

...这给出了一个错误。

如何删除 twothree从列表中使用“二”和“三”来引用它们?

最佳答案

myList[which(names(myList) %in% c("two","three"))] <- NULL

关于显式删除列表的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16778161/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com