I am trying to obtain a subset of a named list, based on element present in another list.
nammedlist<-list( "a"=c(1,2,3,4), "b"=c(2,4,5), "c"=c(9,5,3,2))
selection<-c("a","c")
desired output:
namedlist2<-list( "a"=c(1,2,3,4), "c"=c(9,5,3,2))
I am considering writing a for loop checking for each name if it is present and then extracting it. But their must be a cleaner way to do this.