[R] Surprise when mapping matrix to image

strinz@freenet.de strinz at freenet.de
Fri Nov 18 14:07:55 CET 2005


Hello,

I wonder if 
image(t(x)[ncol(x):1, ])
can do the job correct!

perhaps this does the job better:

image(t(x)[,nrow(x):1])

Björn



From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Fri 27 Aug 2004 - 06:43:50 EST


On Thu, 26 Aug 2004, Glynn, Earl wrote:

> Start with:
>
> > x <- c(1:7,1)
> > dim(x) <- c(2,4)
> > x
> [,1] [,2] [,3] [,4]
> [1,] 1 3 5 7
> [2,] 2 4 6 1
>
> 2 Rows of 4 Columns. Upper-left and lower-right elements of the matrix
> are the same.
>
> All to this point makes good sense.

It's pure convention: see below.

> > image(x)
>
> However, this image shows 2 columns of 4 rows. The lower-left and
> upper-right elements are the same. This does not make sense to me.
> Did I miss some simple parameter to "fix" all of this naturally? Why
> would the numeric matrix of "x" and the image of "x" have such a
> different geometry?

Did you try reading the help for image? You don't seem to understand it if you actually did. It seems you are looking for

        image(t(x)[ncol(x):1, ])

Easy!

Mathematical conventions are just that, conventions. They differ by field of mathematics. Don't ask us why matrix rows are numbered down but graphs are numbered up the y axis, nor why x comes before y but row before column. But the matrix layout has always seemed illogical to me.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html




"Jetzt Handykosten senken mit klarmobil - 15 Ct./Min.! Hier klicken"
www.klarmobil.de/index.html?pid=73025




More information about the R-help mailing list