I have one large dataframe (~ 130,000 rows) containing local variables and another large dataframe (~ 7,000 rows) containing view density. Both have x and y coordinates, but these coordinates do not always match. eg:
df1 <- data.frame(X = c(2,4,1,2,5), Y = c(6,7,8,9,8), V1 = c("A", "B", "C", "D", "E"), V2 = c("G", "H", "I", "J", "K"))
and
df2 <- data.frame(X = c(2,4,6), Y = c(5,9,7), Dens = c(12, 17, 10))
I would like to add a column to df1 containing the density (Dens) of df2 if the point is close enough. If there is no point close, I would like it to display as NA. eg:
X Y V1 V2 Dens
2 6 A G 12
4 7 B H NA
1 8 C I 17
2 9 D J NA
5 8 E K 10