[R] persp() problem

David Winsemius dwinsemius at comcast.net
Sat Nov 19 22:32:04 CET 2011


On Nov 19, 2011, at 3:19 PM, John Benning wrote:

> Hi, and thanks in advance for any assistance,
>
> I'm new to R and to this mailing list, and am having trouble with  
> the *
> persp()* function. I've got a matrix (z) of values for various  
> combinations
> of x and y, each of which is a set of (0, 5, 10, 15, 20). But when I  
> try *
> persp(x,y,z)*, I get an "*invalid z argument*" error, and when I try  
> simply
> *persp(z)*, R returns an "*invalid x argument*" error, along with  
> warning
> messages. It seems like a very simple problem, so excuse my  
> ignorance, but
> any help would be greatly appreciated. Below is the printout from the
> console.
>
> Many thanks,
>
> john
> --------------------------------------------------------
>
> *> x*
> *[1]  0  5 10 15 20*
> *
> *
> *> y*
> *[1]  0  5 10 15 20*
> *
> *
> *> z*
> *     [,1]  [,2]   [,3]   [,4]   [,5]  *
> *[1,] 4.538 9.169  23.518 32.794 39.322*
> *[2,] 5.013 13.104 33.282 42.202 45.474*
> *[3,] 5.296 17.728 36.989 43.89  46.57 *
> *[4,] 5.366 20.94  39.244 44.987 47.177*
> *[5,] 5.642 23.396 40.842 45.489 47.126*
> *
> *
> *> persp(x,y,z)*
> *Error in persp.default(x, y, z) : invalid 'z' argument*

Unable to reproduce. Maybe z is not a 5 x 5 matrix?

 > x <-scan()
1:  0  5 10 15 20
6:
Read 5 items
 >  y <-scan()
1:   0  5 10 15 20
6:
Read 5 items
 >  z <-matrix(scan(),5,5);
1:  4.538 9.169  23.518 32.794 39.322
6:  5.013 13.104 33.282 42.202 45.474
11:  5.296 17.728 36.989 43.89  46.57
16:  5.366 20.94  39.244 44.987 47.177
21:  5.642 23.396 40.842 45.489 47.126
26:
Read 25 items
 > persp(x,y,z)

Attached.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Rplot.pdf
Type: application/pdf
Size: 21985 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20111119/6cd5cfc0/attachment.pdf>
-------------- next part --------------


David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list