r - Accessing list element using grep -


how can directly access list item using grep output? far, found indirect way works involving unlisting both list , grep output:

list1 <- list(c("group1", "group2", "group3")) list2 <- list(c("groupa", "groupb", "groupc")) list.all <- c(list1,list2)                

the following code works, i'm looking alternative unlist()

idx <- unlist(lapply(list.all, function(x) grepl("group1", x))) unlist(list.all)[idx] 

returns "group1" expected.

what looking syntax-wise - doesn't work - access list element directly like:

list.all[[id.index]] 

but returns > invalid subscript type 'list'

any ideas appreciated!


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -