【发布时间】:2015-12-04 00:53:44
【问题描述】:
尽管@jeremycg 帮助我开发了以下代码,但我再次发布此内容。它有效,但它的表现不是我想要的! 快速提醒:我有一组树,我需要根据一个称为 gamma 的因子进行测量,如果每棵树的值不在定义的范围内,它会重新缩放,直到它的值在定义的范围内......让我们试试这个例子:
library(ape)
library(phytools)
trees<- pbtree(b=1, n=100, nsim=50)
fixmytrees <- function(tree, rescaleamt = NULL){
if(is.null(rescaleamt)){
rescaleamt <- sample(seq(from = 0.1, to = 0.9, by = 0.1), 1)
}
if(is.na(gammaStat(tree))){return("bad tree")}
if(gammaStat(tree) < 6){
return(tree)
} else {
return(rescale(tree, model ="delta", rescaleamt))
}
}
z<-lapply(tree, fixmytrees)
#The script does rescale trees but they are not extreme enough. In this case if you try
gammaStat(z[[]]) #You would probably see values lower than 6 and sometimes NA!!!
谢谢!
【问题讨论】:
-
偶发错误:较长的对象长度不是较短对象长度的倍数
标签: r loops tree data-manipulation phylogeny