A similar question was asked [here](https://stackoverflow.com/questions/71328721/how-to-find-which-grid-cell-my-point-is-in-using-r). However, the solution doesn't seem to work for me. I am trying to find the grid reference for a given point. For example, if I have a grid and a point that looks like this: [![grid](https://i.stack.imgur.com/1DW1k.png)](https://i.stack.imgur.com/1DW1k.png)

We can see that my point is in grid reference: (53.0, -7). So, in my data, I have a data frame of points that I want to find the grid reference for. For example, if my data looks like this:

```
 # data frame of points I want to find on the grid
    df1 <- data.frame(place = paste0("p", 1:10),
                      lon = c(-6.855823,-6.200411,-6.452618,-7.638343,-7.810404,-7.810404,-6.739738,-6.108979,-8.585729,-7.325793),
                      lat = c(53.38225,53.16652,53.05181,53.04949,52.16302,52.16302,53.46026,53.13494,52.31639,53.34612))
set.seed(22)
# data frame containing the grid
df2 <- data.frame(lon = rep(seq(-8.5, -6.5, 0.1), 16),
                  lat = rep(seq(52,53.5, 0.1), each = 21),
                  var = rnorm(16*21))

```

What Im trying to do is select the `var` in `df2` that corresponds to the grid reference for each of my points in `df1`

For clarity, if I take the point `df1[1,]` we have:

```
place       lon      lat
1    p1 -6.855823 53.38225

```

This corresponds to row 291 in `df2`. Then once, I have the row, I want to get the `var` value for that row.

Any suggestions as to how I could do this?

Additionally, in my real data `df2` has about 5 figures after the decimal point... don't know if this makes a difference, but I thought I should mention it.