Skip to content
Prev 277947 / 398506 Next

persp() problem

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