[R] Subsetting a list of lists using lapply

Charles Berry ccberry at ucsd.edu
Fri Feb 20 04:53:04 CET 2015


Aron Lindberg <aron.lindberg <at> case.edu> writes:

> 
> Hi Everyone,
> 
> I'm working on a thorny subsetting problem involving list of lists. I've put a 
dput of the data here:
> 
> 	https://gist.githubusercontent.com/aronlindberg/b916dee897d051ac5be5/
raw/a78cbf873a7e865c3173f943ff6309ea688c653b/dput
> 


IIUC, you want the value of every list element that is named "sha" and 
that name will only apply to atomic objects.

If so, this should do it. 

> input <- dget("/tmp/dpt")
> shas <- unlist( input, use.names=FALSE )[ grepl( "sha", names(unlist(input)))]
> input[[67]]$content[[1]]$sha
[1] "58cf43ecdc1beb7e1043e9de612ecc817b090f15"
> which(input[[67]]$content[[1]]$sha == shas )
[1] 194


HTH,

Chuck



More information about the R-help mailing list