如何从列表中删除元素? [英] How can I remove an element from a list?
问题描述
我有一个列表,我想从中删除一个元素。我怎么能这样做?
I have a list and I want to remove a single element from it. How can I do this?
我已经尝试查找我认为这个函数的明显名称会出现在参考手册中而我找不到任何合适的东西。
I've tried looking up what I think the obvious names for this function would be in the reference manual and I haven't found anything appropriate.
推荐答案
我根本不知道R,但是有点创意的谷歌搜索引领我到这里: http://tolstoy.newcastle.edu.au/R/help/05/04/1919.html
I don't know R at all, but a bit of creative googling led me here: http://tolstoy.newcastle.edu.au/R/help/05/04/1919.html
来自那里的关键报价:
我没有找到R的明确文档如何从列表中删除元素,但试验和错误告诉我
I do not find explicit documentation for R on how to remove elements from lists, but trial and error tells me
myList [[5]]< - NULL
myList[[5]] <- NULL
将删除第5个元素,然后关闭由删除该元素引起的洞。这就是索引值的结果,所以我必须小心删除元素。我必须从列表的后面到前面工作。
will remove the 5th element and then "close up" the hole caused by deletion of that element. That suffles the index values, So I have to be careful in dropping elements. I must work from the back of the list to the front.
A 以后在帖子中对该帖子的回复说明:
要删除列表中的元素,请参阅R FAQ 7.1
For deleting an element of a list, see R FAQ 7.1
并且相关章节的R FAQ 说:
...不要将x [i]或x [[i]]设置为NULL,因为这将从列表中删除相应的组件。
... Do not set x[i] or x[[i]] to NULL, because this will remove the corresponding component from the list.
这似乎告诉你(以某种向后的方式)如何删除元素。
Which seems to tell you (in a somewhat backwards way) how to remove an element.
希望有所帮助,或至少引导您朝着正确的方向前进。
Hope that helps, or at least leads you in the right direction.
这篇关于如何从列表中删除元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!