[R] How to use curve() function without using x as the variable name inside expression?

Rui Barradas ruipbarradas at sapo.pt
Thu Jan 29 23:25:33 CET 2015


Hello,

The following will work, but I don't know if it's what you want. func2 
will get x and y from the global environment.

func2 <- function(mu){
    x + y + mu ^ 2
}

curve(func2, from = 0, to = 10)


Hope this helps,

Rui Barradas

Em 29-01-2015 21:02, C W escreveu:
> Hi all,
>
> I want to graph a curve as a function of mu, not x.
>
> Here's the R code:
>
> x <- rnorm(10)
> y <- rnorm(10)
>
> func <- function(x, y, mu){
>     x + y + mu ^ 2
> }
>
> curve(f = func(x = x, y = y, mu), from = 0, to = 10)
> I know I can change variable mu to x, but is there a way to tell R that mu
> is the variable of interest, not x.
>
> Thanks in advance,
>
> Mike
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>



More information about the R-help mailing list