R Select multiple items from the list.

I have a list in R of approximately 10,000 items. Say I want to select only elements 5, 7, and 9. I'm not sure how to do this without a for loop.

I want to do something like mylist[[c(5,7,9]] , but that will not work. I also tried the lapply function, but could not get this to work.

+48
list r subset
Aug 25 2018-12-12T00:
source share
1 answer

mylist[c(5,7,9)] should do this.

You want the sublists to be returned as lists of a list of results; you do not use [[]] (or rather, the [[ ) function for this - as Dason notes in the comments, [[ captures the element.

+91
Aug 25 2018-12-12T00:
source share
— -



All Articles