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 ______________________________________________ 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.