明确删除列表中的元素 [英] Remove elements of a list explicitly

查看:77
本文介绍了明确删除列表中的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个列表:

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,并且我想使用两个"和三个"来引用这些元素.我已经尝试过:

I want to remove two and three from the list and I want to refer to these elements using "two" and "three". I've tried:

myList <- myList[[-c("two", "three")]]

...这会导致错误.

...which gives an error.

如何从列表中删除twothree并使用两个"和三个"来引用它们?

How can I remove two and three from the list and refer them using "two" and "three"?

推荐答案

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

这篇关于明确删除列表中的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆