A) Relying on floating point numbers for predictable indexing is a recipe for 
failure. Convert your floating point numbers to integers before using them to 
index.

B) Row and column labels are strings, and you are giving numerics to the 
brackets. You would need to use as.character() on ddr$x and ddr$y in order to 
utilize labels for indexing.
---------------------------------------------------------------------------
Jeff Newmiller The ..... ..... Go Live...
DCN:<jdnew...@dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

Daisy Englert Duursma <daisy.duur...@gmail.com> wrote:

Hello,

I think this is a simple problem but I am not coming up with a simple
solution. I think it just an indexing problem.

I can easily replace values in a matrix from a dataframe when the
dataframe has row and column numbers. In the example below I use row
and column names and  I can not get it to work

#make a matrix where rows and columns are the lat and long for a
bounding box of Australia and all elements have the value of -9990

bb<-matrix(c(rep(-9999,691*886)),nrow=691
,ncol=886,dimnames=list(seq(-10,-44.50,by=-0.05),seq(112,156.25,by=0.05)))

#dfr with row names and col names and values to be replaced in the matrix

dfr <- data.frame(cbind(x=seq(120,125,by=0.05), y=-25, var.1=1))

#insert the values from the dfr into the matrix
bb[dfr$x,dfr$y]<-d$var.1

Thanks for your help,
Daisy



-- 
Daisy Englert Duursma
Department of Biological Sciences
Room E8C156
Macquarie University, North Ryde, NSW 2109
Australia

Tel +61 2 9850 9256

_____________________________________________

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.


        [[alternative HTML version deleted]]

______________________________________________
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