Jack
Jack

Reputation: 165

how to extract from multiphylo object based on tree number?

Is there anyway I can pull out a subset of trees from a multiplylo object based on tree numbers?

    library(phytools)
    tree_list<- pbtree(b=1, n=100, nsim=50) #create 50 trees

Let's say I need to pull out the following trees from tree_list :1,12,26,35

Thanks.

Upvotes: 0

Views: 911

Answers (2)

Nancy
Nancy

Reputation: 4109

If you want another list of trees that only includes select trees like you mentioned, try subsetting with one bracket. You can then rename the trees to match the trees you subsetted.

tree_list = tree_list[c(1,12,26,33)]
names(tree_list) = c(1,12,26,33)
tree_list[["12"]]

Upvotes: 2

C_Z_
C_Z_

Reputation: 7806

To get a sublist from your list, use single brackets [

tree_list[c(1, 12, 26, 35)]

To index the actual object inside a list, use double brackets [[

tree_list[[1]]

Upvotes: 3

Related Questions