Extacting means from a loop generating vectors.

Im very new to R and am getting stuck on what I thought would be the easiest part of what im trying to do. Im generating numbers at 5 time points and looping the simulation, but am stuggling to return the means of the generated numbers. The data frame is;

time, n
1 , n1
2 , n2
3 , n3
4 , n4
5 , n5

Nsp<-c()
for(i in 1:10) {
tree<-sim.bd(b=0.308, d=0.2926, n0=5448, times=0:4)
Nsp[i]<- rowMeans(tree[c("n")])
}

However this doesnt work as I am only selecting one value for in each row. Ive tried 'Nsp[i]<- rowMeans(subset(tree, select = c(n)))' however this gives the error 'number of items to replace is not a multiple of replacement length'. I though extracting the averages of the values created was the simple part.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.