[R] Help with programming a tricky algorithm

Andrew Crane-Droesch andrewcd at gmail.com
Sat Oct 20 09:36:55 CEST 2012


Hi All,

I'm a little stumped by the following problem.  I've got a dataset with 
the following structure:

idxy    ix    iy    country    (other variables)
1        1    1    c1            x1
2        1    2    c1            x2
3        1    3    c1            x3
.        .        .       .            .

3739    55    67    c7        x3739
3740    55    68    c7        x3740

where ix and iy are interger-valued indices of the actual x and y 
coordinates for the gridded data

I want to define a "border" variable that equals 1 if the cell north, 
east, west, or south of it has a different value of the country 
variable.  So, for the row with idxy = 1, border would equal 1 if there 
is any idxy with country !=c1 and ix = 2 (or zero) or iy = 2 (or zero).

Any thoughts?

Thanks!
Andrew



More information about the R-help mailing list