That's what I want. Thank you so much. Lisa
Henrique Dallazuanna wrote: > > Try this: > > my.f <- function(a, b) { > x1 <- 2 * 3 > x2 <- 3 / 6 > x3 <- 4 * 4 / 5 - sqrt(2) > y <- get(deparse(substitute(a))) + get(deparse(substitute(b))) > return(y) > } > > my.f(x1, x2) > > On Fri, Jan 8, 2010 at 4:15 PM, Lisa <lisa...@gmail.com> wrote: >> >> Dear all, >> >> I have a question about how to set arguments in my own function. For >> example, I have a function that looks like this: >> >> my.f <- function(a = x1, b = x2) >> { >> x1 = equation 1 >> x2 = equation 2 >> x3 = equation 3 >> y = a + b >> } >> >> x1, x2, and x3 are temporary variables (intermediate results) calculated >> from other variables within the funciton. I want to use two of these >> three >> variables to calculate y, and write R script as below: >> >> my.f(a = x1, b = x2) >> >> or >> >> my.f(a = x2, b = x3) >> >> The error information shows that: “objects 'x1', 'x2', or 'x3' not >> found”. >> >> Can anybody help me solve this problem? Thanks in advance. >> >> Lisa >> >> -- >> View this message in context: >> http://n4.nabble.com/Arguments-of-a-function-tp1009883p1009883.html >> Sent from the R help mailing list archive at Nabble.com. >> >> ______________________________________________ >> 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. >> > > > > -- > Henrique Dallazuanna > Curitiba-Paraná-Brasil > 25° 25' 40" S 49° 16' 22" O > > ______________________________________________ > 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. > > -- View this message in context: http://n4.nabble.com/Arguments-of-a-function-tp1009883p1009932.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ 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.