jeudi 20 juillet 2017

subtract data from lat/lon coordinates

I have 2 files of data that looks like this:

Model Data
long  lat   count
96.25 18.75     4
78.75 21.25     3
86.75 23.25     7
91.25 33.75     10

Observation Data
long  lat   count
96.75 25.75    10
86.75 23.25     7
78.75 21.25    11
95.25 30.25     5

I'm trying to subtract the counts of the lat/long combinations (model data-observation data) that match such that the first combination of 78.75 & 21.25 would give a difference count of -8. Any lat/long points without a match to subtract with would just be subtracted by or from 0.

I've tried an if statement as such to match points for subtraction:

if (modeldata$long == obsdata$long & modeldata$lat == obsdata$lat) {
      obsdata$difference <- modeldata$count - obsdata$count
 }

However, this just subtracts rows in order, not by matching points, unless matching points happen to fall within the same row.

I also get these warnings:

Warning messages:

1: In modeldata$long == obsdata$long : longer object length is not a multiple of shorter object length

2: In modeldata$lat == obsdata$lat : longer object length is not a multiple of shorter object length

3: In if (modeldata$long == obsdata$long & modeldata$lat == : the condition has length > 1 and only the first element will be used

Any help would be greatly appreciated!

Aucun commentaire:

Enregistrer un commentaire