Hi!

I have a matrix defined on geographical positions (through) row and column 
names. I need to change a number of elements in this matrix using the 
information of a data.frame containing geographical positions and a number of 
variables.

Changing the value of one specific element is easy, but changing on a number 
of selected positions seems more difficult. When I use the geographical 
positions of the data.frame as index, blobs are changed and not individual 
elements.

How can I circumvent this feature of R?

E.g: in this situation I would like the downward diagonal to be changed, not 
the square box...

> tmpmat <- 
matrix(NA,nrow=9,ncol=10,dimnames=list(formatC(tmplat,format="f",digits=2),formatC(tmplon,format="f",digits=2)))
> tmpmat
      8.00 9.50 9.75 14.25 15.00 15.75 18.00 20.50 21.75 25.25
55.25   NA   NA   NA    NA    NA    NA    NA    NA    NA    NA
56.75   NA   NA   NA    NA    NA    NA    NA    NA    NA    NA
57.75   NA   NA   NA    NA    NA    NA    NA    NA    NA    NA
58.00   NA   NA   NA    NA    NA    NA    NA    NA    NA    NA
59.50   NA   NA   NA    NA    NA    NA    NA    NA    NA    NA
62.75   NA   NA   NA    NA    NA    NA    NA    NA    NA    NA
64.50   NA   NA   NA    NA    NA    NA    NA    NA    NA    NA
66.25   NA   NA   NA    NA    NA    NA    NA    NA    NA    NA
67.25   NA   NA   NA    NA    NA    NA    NA    NA    NA    NA
> tmpmat[c("58.00","59.50","62.75"),c("15.00","15.75","18.00")] <- 300
> tmpmat
      8.00 9.50 9.75 14.25 15.00 15.75 18.00 20.50 21.75 25.25
55.25   NA   NA   NA    NA    NA    NA    NA    NA    NA    NA
56.75   NA   NA   NA    NA    NA    NA    NA    NA    NA    NA
57.75   NA   NA   NA    NA    NA    NA    NA    NA    NA    NA
58.00   NA   NA   NA    NA   300   300   300    NA    NA    NA
59.50   NA   NA   NA    NA   300   300   300    NA    NA    NA
62.75   NA   NA   NA    NA   300   300   300    NA    NA    NA
64.50   NA   NA   NA    NA    NA    NA    NA    NA    NA    NA
66.25   NA   NA   NA    NA    NA    NA    NA    NA    NA    NA
67.25   NA   NA   NA    NA    NA    NA    NA    NA    NA    NA

While I wanted:
> tmpmat
      8.00 9.50 9.75 14.25 15.00 15.75 18.00 20.50 21.75 25.25
55.25   NA   NA   NA    NA    NA    NA    NA    NA    NA    NA
56.75   NA   NA   NA    NA    NA    NA    NA    NA    NA    NA
57.75   NA   NA   NA    NA    NA    NA    NA    NA    NA    NA
58.00   NA   NA   NA    NA   300    NA   NA    NA    NA    NA
59.50   NA   NA   NA    NA    NA   300   NA    NA    NA    NA
62.75   NA   NA   NA    NA    NA    NA   300    NA    NA    NA
64.50   NA   NA   NA    NA    NA    NA    NA    NA    NA    NA
66.25   NA   NA   NA    NA    NA    NA    NA    NA    NA    NA
67.25   NA   NA   NA    NA    NA    NA    NA    NA    NA    NA

All the best
Øystein
-- 
Dr. Oystein Godoy
Norwegian Meteorological Institute 
P.O.BOX 43, Blindern, N-0313 OSLO, Norway
Ph: (+47) 2296 3000 (switchb) 2296 3334 (direct line)
Fax:(+47) 2296 3050 Institute home page: http://met.no/

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to