i'm stuck and frustrated.
I have two data frames:
A: one large dataset (4900000+ rows) with temperatures, latitude and longitude, date.
temp <- c(sst, lat, lon, date)
B: one with 209 polygon names and coordinate boundaries (North, South, East and West).
icesrect <- c(AreaCode, SOUTH,EAST, NORTH, WEST)
For each row in A I need to find which polygon(B) that A's coordinates fits within, and then assign said polygon name to the row in A. The final product should look likes this c(sst, lat, lon,date AreaCode).
I know it can be done with the in.polygon function, but the 209 polygons makes it extremely tedious.
I figure that a for loop is the way to go, and i have tried this:
for (i in c(1:nrow(temp))){
indes <- which(((temp$lat[i] > icesrect$SOUTH) & (temp$lat[i] < icesrect$NORTH) & (temp$lon[i] > icesrect$WEST) & (temp$lon[i] < icesrect$EAST )))
temp$AreaCode[i] <- icesrect$AreaCode[indes] }
Unfortunately this doesn't work.
I hope someone can help!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…