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 -

python - ValueError: No axis named 1 for object type <class 'pandas.core.series.Series'> -

java - How to provide dependency injections in Eclipse RCP 3.x? -