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
?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
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
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.
__
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])
}
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
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
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
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
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
10 matches
Mail list logo