RE: [R] Ploting a function of two arguments

From: Liaw, Andy <andy_liaw_at_merck.com>
Date: Fri 11 Mar 2005 - 13:48:51 EST


There are at least two options:

  1. Use outer(); e.g., something like z <- outer(x, y, f).
  2. Use expand.grid(x, y), then call f() with the output.

Andy

> From: Martin C. Martin
>
> Hi,
>
> I've written a function:
>
> myfun <- function(x, y) {
> // blah blah
> }
>
> and I want to graph it. My plan is to use persp(), and my
> question is:
> how do I create the array of values? One possibility is:
>
> x <- seq(0, 10, by=.1)
> y <- seq(0, 10, by=.1)
>
> inputs <- <somehow create an array of x,y pairs>
>
> outputs <- apply(A, c(1,2), myfun)
>
> The "inputs" array would need to be 101x101x2 array, i.e.
> basically a 2D
> array of pairs. I might need to write a little wrapper for myfun.
>
> Am I on the right track, or is there an easier way to do
> this? It seems
> there should be an easier way to graph a 2 argument function
> like this.
>
> - Martin
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
>
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Fri Mar 11 13:58:54 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:30:42 EST