mercredi 10 mars 2021

find location of elements in a list for multiple patterns in R

i have a list with character elemnts and i need the location of several patterns i need to extract it from the $ tip.label i can do it for one pattern with

lapply(complete.tree, function(ch) grep("Scaptotrigona_tricolorata", ch))$tip.label

but how can i do it for several very different patterns?? i tried a loop

for (i in species) {
 x[i]= lapply(complete.tree, function(ch) grep("i", ch))$tip.label

}

"species" is a vector with all the names i need

any advise will help! this is the list

> str(complete.tree)
List of 5
 $ edge       : int [1:332, 1:2] 168 169 170 170 171 172 173 173 174 175 ...
 $ edge.length: num [1:332] 24.2 0 77.8 39.38 2.63 ...
 $ Nnode      : int 166
 $ node.label : chr [1:166] "54" "133" "135" "71" ...
 $ tip.label  : chr [1:167] "Bombus" "Scaptotrigona_polysticta" "Scaptotrigona_sp._B_CR-2009" "Scaptotrigona_sp._A_CR-2009" ...
 - attr(*, "class")= chr "phylo"
 - attr(*, "order")= chr "cladewise"

Aucun commentaire:

Enregistrer un commentaire