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

'hasOwnProperty' in javascript -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -

How to understand 2 main() functions after using uftrace to profile the C++ program? -