Say I have a large set of data in R that has variables latitude, longitude, magnitude, and depth (for earthquakes) and I want to create a new data set that includes data for all the variables but only between certain values of latitude and longitude. For example, I want earthquakes that are between 0 and 50 longitude and -20 and 45 latitude (but I want the magnitude and depth to still correspond to the correct longitude and latitudes). Is there an easy way to do this R? For example:
latitude longitude magnitude depth
45 45 1.0 5
-10 -10 4.5 6
-76 12 2.435 18
and I want to choose data where the latitude is between -80 and 0 and the longitude is between 0 and 50, so the only column that would match would be:
latitude, longitude magnitude depth
-76 12 2.435 18
How can I do this?