[R] persp() problem

William Dunlap wdunlap at tibco.com
Sat Nov 19 22:57:31 CET 2011


The trailing space (instead of '0') in the
third line of the printout of z, the fact that
the decimal points are not aligned in the columns,
and the left- justification of the column labels
are hints that z is not a matrix of numbers, but just
prints something like one.
  *> 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 *
E.g., compare the printouts of the following:
  > pNumeric <- matrix((1:6)*5.125, 3, 2)
  > pCharacter <- noquote(matrix(as.character((1:6)*5.125), 3, 2))
  > pNumeric
         [,1]   [,2]
  [1,]  5.125 20.500
  [2,] 10.250 25.625
  [3,] 15.375 30.750
  > pCharacter
       [,1]   [,2]  
  [1,] 5.125  20.5  
  [2,] 10.25  25.625
  [3,] 15.375 30.75
This is why R-help encourages people to show datasets
using the output of dput(), which shows more of the
actual structure of the data.
  > dput(pNumeric)
  structure(c(5.125, 10.25, 15.375, 20.5, 25.625, 30.75), .Dim = c(3L, 
  2L))
  > dput(pCharacter)
  structure(c("5.125", "10.25", "15.375", "20.5", "25.625", "30.75"
  ), .Dim = c(3L, 2L), class = "noquote")

persp() gives odd error messages when x, y, or
z is not numeric; it does not just say that character
data is not allowed.

Try reentering your data and looking at the
output of str(z), str(x), and str(y) to make
sure they are all numeric and that z is a matrix.
  > str(pNumeric)
   num [1:3, 1:2] 5.12 10.25 15.38 20.5 25.62 ...
  > str(pCharacter)
   'noquote' chr [1:3, 1:2] "5.125" "10.25" "15.375" "20.5" "25.625" "30.75"

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of John Benning
> Sent: Saturday, November 19, 2011 12:20 PM
> To: r-help at r-project.org
> Subject: [R] persp() problem
> 
> 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*
> *
> *
> *> persp(z)*
> *Error in persp.default(z) : invalid 'x' argument*
> *In addition: Warning messages:*
> *1: In min(x, na.rm = na.rm) :*
> *  no non-missing arguments to min; returning Inf*
> *2: In max(x, na.rm = na.rm) :*
> *  no non-missing arguments to max; returning -Inf*
> *3: In min(x, na.rm = na.rm) :*
> *  no non-missing arguments to min; returning Inf*
> *4: In max(x, na.rm = na.rm) :*
> *  no non-missing arguments to max; returning -Inf*
> *5: In min(x, na.rm = na.rm) :*
> *  no non-missing arguments to min; returning Inf*
> *6: In max(x, na.rm = na.rm) :*
> *  no non-missing arguments to max; returning -Inf*
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> 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