'Convert data frame to spatial object and find the polygon that contains a point

I have two data frames. The first contains the longitude and latitude coordinates for a series of locations. And it looks like this:

df1

The second data frame contains gridded data, the head is as follows. The longitude range is (-10.70, -5.35) and the latitude range is (51.33, 55.38).

df2

I need to find the grid that contains the value of each city given in data frame 1. Do I need to convert it to a spatial object or is it possible to do it directly from the data frames? How can I do that?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source