[R] x,y vs row,column
yudi@pop3.ucd.ie
yudi at pop3.ucd.ie
Thu May 6 19:16:34 CEST 1999
> From: Bill Simpson <wsimpson at gcal.ac.uk>
> Subject: [R] x,y vs row,column
> I think my problems are coused by a fundamental R incompatibility in how
> matrices are stored and the usual way of specifying Cartesian coordinates.
> 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
> 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.
This is standard not just for 'stats people', but also in Fortran,
which by default assumes numbers are read column-wise.
(In computer memory column-wise numbers are contiguous.)
In matrix algebra we always refer to the row of the matrix first
e.g., (x,y)-element refers to row-x-and-column-y element.
So the mismatch between the matrix reading/printing/referencing
and the Cartesian plot as in image() is not unique of R. The
geometric mismatch is actually necessary so we can still refer
to the same (x,y) element in the matrix and in the plot.
>But when I do:
>image(x,y,z, col=gray(0:19/19),xlab="Lag 1 (s)", ylab="Lag 2 (s)")
>So I do:
>image(y,x,z, col=gray(0:19/19),xlab="Lag 1 (s)", ylab="Lag 2 (s)")
>And the plot is exactly the same!!
>What is going on, and how to fix? Thanks very much for any help.
x and y in image will only affect the axes, the image itself is
determined by matrix z, i.e., you could do > image(z).
To fix? well, just remember rows of a matrix are image()'d
column-wise.
------------------------------
Yudi Pawitan: yudi at ucd.ie
Department of Statistics, UCD
Dublin 4, Ireland
Ph : 353-1-706 7641
Fax: 353-1-706 1186
------------------------------
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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