[R] x,y vs row,column

Thomas Lumley thomas at biostat.washington.edu
Thu May 6 17:32:26 CEST 1999


On Thu, 6 May 1999, Bill Simpson wrote:

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

> 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.

It is somewhat standard. It probably comes from having to work with only
two-dimensional data structures, which makes it logical to have one
dimension indexing records and the other indexing variables.  Spatial data
would then be stored with columns x,y,d1,d2,d3 for multiple data fields
d1-d3. 

For data observed on a rectangular grid it might well be better to use a
3-d array with d1-d3 on slices of the array. But even for spatial data if
they are observed on some other grid (like the triangular equal area grids
used for some global-scale satellite data) or at irregular points it
doesn't help at all.

There may, on the other hand, be a good case for having image() work the
other way, though you could just do image(x,y,t(z)) to transpose the z
matrix.


Thomas Lumley
Assistant Professor, Biostatistics
University of Washington, Seattle




-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list