Hi Ivan. Try this simple code:
## load packages library(phytools) library(phangorn) ## get tips descended from each node dd<-Descendants(tree,node=1:tree$Nnode+Ntip(tree), type="tips") names(dd)<-1:tree$Nnode+Ntip(tree) ## get the NUMBER of tips from each node nn<-sapply(dd,length) ## get corresponding node indices nodes<-as.numeric(names(nn[which(nn==2)])) ## compute their heights above root heights<-setNames(sapply(nodes,nodeheight, tree=tree),nodes) This scales well up to trees with 1,000 or more tips IME. It gives you the /heights/ above the root of each node with two descendants (cherry). If your tree is ultrametric, to get the /depth/ you would just subtract this value from the total height of the tree. Let me know if it works!! All the best, Liam Liam J. Revell Professor of Biology, University of Massachusetts Boston Web: http://faculty.umb.edu/liam.revell/ On 1/9/2023 5:37 PM, Ivan Magalhaes wrote: > CAUTION: EXTERNAL SENDER > > Hi all, > Perhaps a dumb question, but is there an easy way to count the number of > cherries in a given tree, and fetch their ages? (i.e. all the nodes with > exactly two descendants) > Thanks! Best,Ivan > -- > Dr. Ivan L. F. Magalhaes > > Postdoctoral fellow — División AracnologíaMuseo Argentino de Ciencias > Naturales "Bernardino Rivadavia" > Av. Ángel Gallardo 470, C1405DJR, Buenos Aires, Argentina+54 11 4982-8370 > ext. 169Website | ResearchGate | Twitter |iNaturalist | Lattes | CV-Ar | > ORCID | GitHub > [[alternative HTML version deleted]] > > _______________________________________________ > R-sig-phylo mailing list -R-sig-phylo@r-project.org > https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-sig-phylo&data=05%7C01%7Cliam.revell%40umb.edu%7C58b9f271e0124a5ff56a08daf292212b%7Cb97188711ee94425953c1ace1373eb38%7C0%7C0%7C638089006703316956%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=xpf1hbFEEJFsi%2BGI3in6yfxNbiThSss5ivqEeiuQS%2BY%3D&reserved=0 > Searchable archive > athttps://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.mail-archive.com%2Fr-sig-phylo%40r-project.org%2F&data=05%7C01%7Cliam.revell%40umb.edu%7C58b9f271e0124a5ff56a08daf292212b%7Cb97188711ee94425953c1ace1373eb38%7C0%7C0%7C638089006703316956%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=wcDMnSGFSQotMzfg05l83bCltDgOkk7SL%2F94LSNhiXQ%3D&reserved=0 [[alternative HTML version deleted]] _______________________________________________ R-sig-phylo mailing list - R-sig-phylo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-phylo Searchable archive at http://www.mail-archive.com/r-sig-phylo@r-project.org/