Skip to content
Prev 149407 / 398498 Next

recursively divide a value to get a sequence

On Wed, 2008-07-09 at 11:40 +0200, Anne-Marie Ternes wrote:
Well, if you really want to do it recursively (and maybe loopy as well)

recursivdiv<-function(x,denom,lendiv,firstpass=TRUE) {
 if(firstpass) lendiv<-lendiv-1
 if(lendiv > 1) {
  divvec<-c(x/denom,recursivdiv(x/denom,denom,lendiv-1,FALSE))
  cat(divvec,ndiv,"\n")
 }
 else divvec<-0
 if(firstpass) divvec<-c(x,divvec)
 return(divvec)
}

Jim