Dear All, Im 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 <- par[1]; x2 <- par[2];x3 <- par[3] ; x4 <- par[4] ; (1+x3)} f4 <-function(par){x1 <- par[1]; x2 <- par[2];x3 <- par[3] ; x4 <- par[4] ; (1+x4)} Each function has four parameters independently on whether a specific variable is explicitly in the function or not. Many thanks for your help! Axel. [[alternative HTML version deleted]]
______________________________________________ R-help@r-project.org 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.