Hello,
I am currently using apTreeshape to simulate phylogenetic trees using the "Yule-Hardy" Method. What I want to do is randomly generate between 20 and 25 different numbers for three different groupings (small, medium and large trees) and then generate about 40 trees for every random number chosen from within the grouping.
I know how I would do this in Python of Matlab, but in R things seem to behave a bit differently.
My thought was that if I were to generate a vector full of random numbers (one for each size grouping) and then use that to generate a vector which would basically contain all of the repeated values of each random number.
Here is what I have:
sm_leaves<-c(sample(3:50,25,replace=F));
s_leafy<-numeric();
for (i in 1:length(sm_leaves)) {
for (j in 1:10) {
s_leafy[j+i-1]=sm_leaves[i];
}
}
This is giving me output like:
> s_leafy
[1] 5 38 6 22 29 20 19 46 9 18 39 50 34 11 43 7 8 32 10 42 14 37
[23] 23 13 28 28 28 28 28 28 28 28 28 28
But What I want is something more like:
> s_leafy
[1] 5 5 5 5 5 5 5 5 5 5 38 38 38 38 38 38 38 38 38 ... 28 28 28 28 28 28 28 28 28 28
My reason for doing this is merely so that I can append this vector to a data frame along with all of the randomly generated trees - I need 2000 of them, so doing this by hand ain't quite practical.
All I have really been able to deduce from my previous attempts to solve this problem is that generally speaking while loops should be used instead of for loops, and many people have talked about using expand.grid, but I don't think that the latter is particularly useful in this case.
Thanks for reading, I hope my problem isn't too trivial (although I wouldn't be surprised if it were).