[R] Subsetting a list of lists using lapply

Charles C. Berry ccberry at ucsd.edu
Fri Feb 20 18:54:58 CET 2015


On Fri, 20 Feb 2015, Aron Lindberg wrote:

> Hmm…Chuck’s solution may actually be problematic because there are several entries which at the deepest level are called “sha”, but that should not be included, such as:
>
>
>
>
>
> input[[67]]$content[[1]]$commit$tree$sha
>
>
>
>
> and
>
>
>
>
> input[[67]]$content[[1]]$parents[[1]]$sha
>
>
>
>
>
> it’s only the “sha” that fit the following subsetting pattern that should be included:
>
>
>
>
>
> input[[i]]$content[[1]]$sha[1]
>
>


This should be straightforward. Look at what grepl() is doing.

And look at what names(unlist(input)) yields.

You can either write a regular expression to handle this (perhaps 
"content.sha$") or write other grepl() expressions to select (or get rid 
of) the desired (or unwanted) pattern.

See ?grepl and the page on regular expression referenced there.

HTH,

Chuck


More information about the R-help mailing list