r - From longitude and latitude to cell number -


i have data frame this

 lonship  latship lonint latint  -179.94  -38.05      1    128  -179.93  -32.54      1    123  -179.93  -32.19      1    122  -179.93  -31.83      1    122  -179.92  -33.97      1    124  -179.92  -33.61      1    124 

what want associate @ each (ordered) pair (lonint,latint) number identify grid cell.

e.g.

 lonship  latship lonint latint cell  -179.94  -38.05      1    128   1  -179.93  -32.54      1    123   2  -179.93  -32.19      1    122   3  -179.93  -31.83      1    122   3  -179.92  -33.97      1    124   4  -179.92  -33.61      1    124   4 

note that, example

(1, 2) != (2,1), i.e. must have 2 different cell number.

can help?

if want ordered pairs need first order multiple columns:

dat<-dat[order(dat$lonint,dat$latint,decreasing=f),] 

then can use simple formula concatenate 2 values. example, if max(latint)<1000 can do:

gridint=dat$lonint*1000+dat$latint 

edit: well, first order not needed formula because ordering following new gridint identifier should give same result.


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -