[R] random binary trees in R

Uwe Ligges ligges at statistik.uni-dortmund.de
Wed Nov 29 18:45:18 CET 2006



Steven Finch wrote:
> Hello!
> 
> I wish to generate random binary trees in R.
> Unfortunately recursive code like:
> 
> t <- function(p)
>   {
>    list(ifelse(runif(1)<p,t(p),0), ifelse(runif(1)<p,t(p),0))
>   }

ifelse() is vectorized and evaluates for both cases!
Instead, try:

t <- function(p)
   list(if(runif(1) < p) t(p) else 0, if(runif(1) < p) t(p) else 0)


Uwe Ligges


> does not seem to work. Has anyone ever
> performed such a simulation?  I would like
> to see their code.  Maybe this is not feasible
> in R.  Please e-mail me at the below address
> (since I am not yet a subscriber to this list).
> Thank you!
> 
> Steve Finch
> sfinch9 at hotmail.com
> 
> _________________________________________________________________
> MSN Shopping has everything on your holiday list. Get expert picks by style, 
> age, and price. Try it!
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list