我只需要在每次循环时保存df并将其保存为csv或类似的东西!
#Q是矩阵,树是phyllo对象
library(ape)
library(phytools)
for(l in 1:length(Q.all)){
for(k in 1:length(trees)){
tree<- trees[[k]]
Q<- Q.all[[l]]
file1<- sim.history (tree, Q, nsim=10)
df<- getStates(file1, type="tips")
df2 <- as.data.frame(matrix(nrow=nrow(df),ncol=length(file1)))
for(i in 1:length(file1)){
for(j in 1:nrow(df)){
x <- df[j,i]
num <- sum(df[,i] == x) - 1
rarity <- 1 - num/(nrow(df)-1)
df2[j,i] <- rarity
}
}
由于