I actually messed up the indices. Should be this: # assumes a tree 'phy' and a dataframe, 'df', with first column of tip names, and second column of values for (i in 1:dim(df)[1]) { # find index of edge length idx <- which(phy$edge[,2] == which(phy$tip.label == df[i,1])); # apply it. this assume you want to extend it, not just set it phy$edge.length[idx] <- phy$edge.length[idx] + as.numeric(df[i,2]); }
That said, I haven't tested, so maybe works? JWB ________________________________________ Joseph W. Brown Post-doctoral Researcher, Smith Laboratory University of Michigan Department of Ecology & Evolutionary Biology Room 2071, Kraus Natural Sciences Building Ann Arbor MI 48109-1079 josep...@umich.edu > On 26 Jul, 2017, at 12:12, William Gearty <wgea...@stanford.edu> wrote: > > Awesome, thanks Joseph! > > On Wed, Jul 26, 2017 at 9:10 AM, Joseph W. Brown <josep...@umich.edu > <mailto:josep...@umich.edu>> wrote: > I think this'll work, depending on how you store your data. > > # assumes a tree 'phy' and a dataframe, 'df', with first column of tip names, > and second column of values > for (i in 1:dim(df)[1]) { > # find index of edge length > idx <- which(phy$edge[,2] == which(phy$tip.label == df[1,i])); > # apply it. this assume you want to extend it, not just set it > phy$edge.length[idx] <- phy$edge.length[idx] + as.numeric(df[i,2]); > } > > Probably a nicer way to do it without a loop... > > JWB > ________________________________________ > Joseph W. Brown > Post-doctoral Researcher, Smith Laboratory > University of Michigan > Department of Ecology & Evolutionary Biology > Room 2071, Kraus Natural Sciences Building > Ann Arbor MI 48109-1079 > josep...@umich.edu <mailto:josep...@umich.edu> > > > >> On 26 Jul, 2017, at 11:57, William Gearty <wgea...@stanford.edu >> <mailto:wgea...@stanford.edu>> wrote: >> >> That's definitely helpful, Joseph, but I'll need to extend the tips to >> varying amounts. >> >> Basically, I performed a tip-dating analysis using constraints based on the >> FADs of a bunch of fossils. >> However, now some of the analyses I want to perform require that the tips >> extend to the species' extinctions, so I need to extend them to the LADs (or >> farther, I suppose). >> How would I, given a vector of LAD ages for the tips, extend the tips to >> those ages? >> >> On Wed, Jul 26, 2017 at 8:50 AM, Joseph W. Brown <josep...@umich.edu >> <mailto:josep...@umich.edu>> wrote: >> If you want to just extend all tips by a constant amount you can do this: >> >> # extend terminal edges by arbitrary amount (here: 13) >> idx <- which(phy$edge[,2] < (phy$Nnode + 1)); >> phy$edge.length[idx] <- phy$edge.length[idx] + 13; >> >> HTH. >> Joseph. >> ________________________________________ >> Joseph W. Brown >> Post-doctoral Researcher, Smith Laboratory >> University of Michigan >> Department of Ecology & Evolutionary Biology >> Room 2071, Kraus Natural Sciences Building >> Ann Arbor MI 48109-1079 >> josep...@umich.edu <mailto:josep...@umich.edu> >> >> >> >>> On 26 Jul, 2017, at 11:39, David Bapst <dwba...@gmail.com >>> <mailto:dwba...@gmail.com>> wrote: >>> >>> Not sure what you mean by extending tips, Will. Could you describe a >>> small example? >>> -Dave >>> >>> On Fri, Jul 21, 2017 at 5:15 PM, William Gearty <wgea...@stanford.edu >>> <mailto:wgea...@stanford.edu>> wrote: >>>> Hi all, >>>> >>>> Before I go ahead and wrote a whole script, I was wondering if there is a >>>> function or script out there for extending tips (or setting the ages of >>>> tips) given a list of taxa and ages? >>>> I haven't found anything, but perhaps I'm searching the wrong phrase(s). >>>> >>>> Thanks, >>>> Will >>>> >>>> -- >>>> William Gearty >>>> PhD Candidate, Paleobiology >>>> Department of Geological Sciences >>>> Stanford School of Earth, Energy & Environmental Sciences >>>> williamgearty.com <http://williamgearty.com/> >>>> >>>> [[alternative HTML version deleted]] >>>> >>>> _______________________________________________ >>>> R-sig-phylo mailing list - R-sig-phylo@r-project.org >>>> <mailto:R-sig-phylo@r-project.org> >>>> https://stat.ethz.ch/mailman/listinfo/r-sig-phylo >>>> <https://stat.ethz.ch/mailman/listinfo/r-sig-phylo> >>>> Searchable archive at >>>> http://www.mail-archive.com/r-sig-phylo@r-project.org/ >>>> <http://www.mail-archive.com/r-sig-phylo@r-project.org/> >>> >>> >>> >>> -- >>> David W. Bapst, PhD >>> https://github.com/dwbapst/paleotree <https://github.com/dwbapst/paleotree> >>> >>> _______________________________________________ >>> R-sig-phylo mailing list - R-sig-phylo@r-project.org >>> <mailto:R-sig-phylo@r-project.org> >>> https://stat.ethz.ch/mailman/listinfo/r-sig-phylo >>> <https://stat.ethz.ch/mailman/listinfo/r-sig-phylo> >>> Searchable archive at >>> http://www.mail-archive.com/r-sig-phylo@r-project.org/ >>> <http://www.mail-archive.com/r-sig-phylo@r-project.org/> >> >> >> >> >> -- >> William Gearty >> PhD Candidate, Paleobiology >> Department of Geological Sciences >> Stanford School of Earth, Energy & Environmental Sciences >> williamgearty.com <http://williamgearty.com/> > > > > > -- > William Gearty > PhD Candidate, Paleobiology > Department of Geological Sciences > Stanford School of Earth, Energy & Environmental Sciences > williamgearty.com <http://williamgearty.com/> [[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/