Re: [R] Help plase with simple loop

2009-03-15 Thread David Winsemius
I don't think you have gotten the basic idea of functions in R. Those functions would return only the value of the last evaluated expression, e.g. (1+par[1]) in the case of f1, but most of the code appears to have no effect. See this simple example: > x1 <- 4 > f1 <- function(x) x1 <- x > f

[R] Help plase with simple loop

2009-03-15 Thread Axel Urbiz
Dear All, I’m a new R user. How can I write code below more efficiently (using a loop for example)? f1 <-function(par){x1 <- par[1]; x2 <- par[2];x3 <- par[3] ; x4 <- par[4] ; (1+x1)} f2 <-function(par){x1 <- par[1]; x2 <- par[2];x3 <- par[3] ; x4 <- par[4] ;(1+x2)} f3 <-function(par){x1 <- p