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)) } 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!
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.
Hello again! Uwe Ligges' adjustment to my random binary tree recursion works beautifully. Now I wish to plot the trees. Despite a careful search, I can't find any plotting routine that will work with my lists. I've read about "hierarchical clustering" and "binary dendrograms" in various R packages, but nothing apparently can take my lists as input. If anyone has solved this problem and can send me the relevant code, I will be very thankful! Please e-mail me at the below address. With much appreciation, Steve Finch sfinch9 at hotmail.com>From: Uwe Ligges <ligges at statistik.uni-dortmund.de> >To: Steven Finch <sfinch9 at hotmail.com> >CC: r-help at stat.math.ethz.ch >Subject: Re: [R] random binary trees in R >Date: Wed, 29 Nov 2006 18:45:18 +0100 > > > >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 >>_________________________________________________________________ All-in-one security and maintenance for your PC.? Get a free 90-day trial!