# [R] x,y vs row,column

Bill Simpson wsimpson at gcal.ac.uk
Thu May 6 15:36:14 CEST 1999

```I think my problems are coused by a fundamental R incompatibility in how
matrices are stored and the usual way of specifying Cartesian coordinates.

When I do
x<-unique(data\$lag1)
y<-unique(data\$lag2)
z<-matrix(data\$cif2d,length(y),length(x))

This z matrix is printed apparently correctly from a Cartesian point of
view
> z
[,1] [,2] [,3]
[1,]   11   21   31
[2,]   12   22   32
[3,]   13   23   33

But if you look at the numbers on the top and side you see that the row
and column indexes have been reversed!  By that I mean in Cartesian system
you do (x,y) which is equiv to (col,row); matrix() prints the numbers
above in accord with (col,row) but they are actually stored as (row,col).

> z[2,1]
[1] 12
whereas I would expect 21.

If this is standard for you stats people that is too bad, in my opinion.
I always think in terms of x,y,z = col, row, height.

So I need to use:
z<-matrix(data\$cif2d,length(y),length(x), byrow=TRUE)

How do you avoid getting mixed up when making an image plot of a matrix?

I like the way persp() is set up, which is NOT the way image() is set up.

Bill Simpson

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

```