Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • 10
    Just to add some more detail - "[" will return a sublist so it makes sense that you could use multiple inputs with it. "[[" will actually grab the element itself so it can only take a single input since it isn't returning a list (unless the element itself is a list). Commented Aug 25, 2012 at 4:15
  • Is this vectorized? I have two lists: b contains 10 million elements. filter_bins is a list where each element is an index. so to only get elements from b with the same index, I have lapply(filter_bins, function(x) b[x, ]) so b[x, ] only returns a subset of the rows (where each element is chosen by filter_bins).. I hope this makes sense. My question is that this is very slow Commented Oct 23, 2014 at 19:35
  • @masfenix you should generate a new question describing the details. Commented Nov 14, 2014 at 8:53
  • Can the above solution be done with something like dplyr::select() and contains('some text")? Commented May 5, 2016 at 17:32
  • 3
    @HermanToothrot You don't. At least not directly. You could lapply or sapply over the indices you want to extract and iteratively grab the corresponding element with [[. But if you want to extract multiple elements then really you're grabbing a sublist and you should just use [ Commented Apr 25, 2018 at 15:44