Skip to content
Prev 292813 / 398498 Next

understanding the FUNCTION function

Simply return it like a function is supposed to:

fac <- function(x, loud = TRUE){
    a <- 1
    for(i in seq_len(x)) { # seq_len is faster and more robust
        a <- a * i
        if(loud) print(a)
    }
    return(a)
}

fac3 <- fac(3)

print(fac3) # As desired

Michael
On Thu, Apr 26, 2012 at 2:16 PM, michaelyb <cel81009759 at gmail.com> wrote: