Re: [R] Arguments of a function

2011-03-18 Thread Lisa
Thank you very much! -- View this message in context: http://r.789695.n4.nabble.com/Arguments-of-a-function-tp3387643p3388615.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailma

Re: [R] Arguments of a function

2011-03-18 Thread Bert Gunter
?do.call ## read it CAREFULLY, please. do.call(runif,as.list(c(1,range))) -- Bert On Fri, Mar 18, 2011 at 9:10 AM, Lisa wrote: > Hi, everybody, > > I just want to pass arguments to a function as below: > > range <- c(0.1, 0.5) > > runif(1, range) > > But it doesn’t work. > > Does anyone have a

[R] Arguments of a function

2011-03-18 Thread Lisa
Hi, everybody, I just want to pass arguments to a function as below: range <- c(0.1, 0.5) runif(1, range) But it doesn’t work. Does anyone have any suggestions to offer? Thanks. Lisa -- View this message in context: http://r.789695.n4.nabble.com/Arguments-of-a-function-tp3387643p3387643

Re: [R] Arguments of a function

2011-03-18 Thread D Kelly O'Day
You need to change your second line: range <- c(0.1, 0.5) runif(1, range[1], range[2]) -- View this message in context: http://r.789695.n4.nabble.com/Arguments-of-a-function-tp3387643p3388400.html Sent from the R help mailing list archive at Nabble.com. __

Re: [R] Arguments of a function

2010-01-09 Thread Gabor Grothendieck
Normally one designs their function to input a formula in such a case rather than design it to take the names directly. Thus: f <- function(formula = ~ x1 + x2) { xs <- c(x1 = 1, x2 = exp(1), x3 = 2*pi) v <- all.vars(formula) stopifnot(length(v) == 2, all(v %in% names(xs))) sum(xs[v]) }

Re: [R] Arguments of a function

2010-01-09 Thread Peter Ehlers
You could define a list and then just access the appropriate elements of that list: my.f <- function(a, b) { x1 = equation 1 x2 = equation 2 x3 = equation 3 L <- list(x1, x2, x3) y <- L[[a]] + L[[b]] } my.f(1,2) my.f(2,3) -Peter Ehlers Lisa wrote: Dear all, I have a question about

Re: [R] Arguments of a function

2010-01-08 Thread Jim Lemon
On 01/09/2010 05:15 AM, Lisa 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 t

Re: [R] Arguments of a function

2010-01-08 Thread Lisa
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(x

Re: [R] Arguments of a function

2010-01-08 Thread Henrique Dallazuanna
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 wrote: > > Dear all, > > I have a question about

[R] Arguments of a function

2010-01-08 Thread Lisa
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 resu