Re: [R] building a spatial matrix

2016-05-16 Thread A M Lavezzi
Hi Sarah, thanks a lot. In this line: result.m[cbind(factor(result$f_cell), factor(result$f_cell_neigh))] <- result$distance I had a problem with cbind(factor .. : the assignement to the [i,j] element of the matrix did not work. I solved in this manner: - I modified censDist, so for every coupl

Re: [R] building a spatial matrix

2016-05-13 Thread A M Lavezzi
*PLEASE IGNORE THE PREVIOUS EMAIL, IT WAS SENT BY MISTAKE* Hello Sarah thanks a lot for your advice. I followed your suggestions unitil the creation of "result" The allocation of the values of result$distance to the matrix result.m, however ,does not seem to work: it produces a matrix with ident

Re: [R] building a spatial matrix

2016-05-13 Thread Sarah Goslee
Sorry, you're right. The result line should be: result.m[cbind(factor(result$fcell), factor(result$cellneigh))] <- result$distance idcell <- data.frame( id = seq_len(5), fcell = sample(1:100, 5)) censDist <- expand.grid(fcell=seq_len(100), cellneigh=seq_len(100)) censDist$distance <- runi

Re: [R] building a spatial matrix

2016-05-13 Thread A M Lavezzi
Hello Sarah thanks a lot for your advice. I followed your suggestions unitl the creation of "result" The allocation of the values of result$distance to the matrix result.m, however ,does not seem to work: it produces a matrix with identical columns corresponding to the last values of result$dista

Re: [R] building a spatial matrix

2016-05-12 Thread Sarah Goslee
I don't see any reason why a loop is out of the question, and answering would have been much easier if you'd included the requested reproducible data, but what about this? This solution is robust to pairs from idcell being absent in censDist, and to the difference from A to B being different than