Skip to content
Prev 348417 / 398500 Next

Subsetting a list of lists using lapply

On Feb 20, 2015, at 6:13 AM, Aron Lindberg wrote:

            
I didn't try on the larger example, but this works on the smaller one:

 get_shas <- function(input){
	x <- lapply(input, "[[", "content")
        y <- lapply(x, "[[", 1)   
	z <- lapply(y, function(yy) if( length(names(yy)) && names(yy) =="sha"  ){ yy[["sha"]] })
	}
      sha_lists <- get_shas(input)

It does deliver an entry for every leaf of the input-object which is either the value of "sha" or NA. I think that is not a bad thing because it lets you figure out where the values are coming from.
David Winsemius
Alameda, CA, USA