Alaios alaios at yahoo.com
Wed Jan 26 08:47:45 CET 2011

```The reason is the following image
http://img545.imageshack.us/i/maptoregion.jpg/
In the picture above you will find the indexes for each cell.

Also you will see that I place that matrix inside a x,y region that spans from -1 to 1. I am trying to write one function that will get as argument a (x,y) value x e[-1,1] y e[-1,1] and will return the indexes of that cell tha x,y value correspond to.

I really do not have a clue how I should try to approach that to solve it. So based on some version I had for 1-d vector I tried to extend it for 2-d. I used findInterval as a core to get results.
Unfortunately my code fails to produce accurate results as my approach 'assumes' (this is something inhereted by the find Interval function) that the numbering starts bottom left and goes high top right.
You will find my code below

sr.map <- function(sr){
# This function converts the s(x,y) matrix into a function x that spans #from -1 to 1 and y spans from -1 to 1.
# Input: sr a x,y matrix containing the shadowing values of a Region
breaksX <- seq(from=-1, to = 1, length = nrow(sr) +1L )
breaksY <- seq(from=-1, to = 1, length = ncol(sr) + 1L)
function(x,y){ # SPAGGETI CODE FOR EVER
indx <- findInterval(x, breaksX,rightmost.closed=TRUE)
indy <- findInterval(y, breaksY,rightmost.closed=TRUE)
c(indx,indy)
}
}

sr<-matrix(data=seq(from=1,to=36),nrow=6,ncol=6,byrow=TRUE)
f.sr.map<-sr.map((sr))
f.sr.map(-0.1,-0.1)
f.sr.map(0.1,0.1)

Best Regards
Alex

--- On Wed, 1/26/11, David Winsemius <dwinsemius at comcast.net> wrote:

> From: David Winsemius <dwinsemius at comcast.net>
> Subject: Re: [R] MAtrix addressing
> To: "Alaios" <alaios at yahoo.com>
> Cc: R-help at r-project.org
> Date: Wednesday, January 26, 2011, 2:54 AM
>
> On Jan 25, 2011, at 4:50 PM, Alaios wrote:
>
> > Hello
> > I would like to ask you if it is possible In R Cran to
> change the default way of addressing a matrix.
> > for example
> > matrix(data=seq(from=1,to=4,nrow=2,ncol=2, by row
> numbering) # not having R at this pc
> >
> > will create something like the following
> > 1 2
> > 3 4
> >
> > the way R address this matrix is from top left corner
> moving to bottom right.
> > The cell numbers in that way are
> > 1 2
> > 3 4
> >
> > IS it possible to change this default addresing number
> to something that goes bottom left to top right? In this
> simple case I want to have
> > 3 4
> > 1 2
> >
> > Would that be possible?
>
> Yes. it's possible but ... why?
>
> >
> > I would like to thank y for your help
> > Regards
> > Alex
> >
> > ______________________________________________
> > R-help at r-project.org
> mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help