Data
I have a shapefile for Ontario province boundary that I read as follows:
library(sf)
library(here)
ontario <- sf::st_read(here::here("data", "messy_data", "Ontario.shp"), quiet = TRUE) %>%
st_transform(4326)
It can be plotted as follows:
Question
I want to keep the ontario
data only for latitude < 51
. But since it is a sf
object, dplyr::filter(latitude < 51)
doesn't work. I know that I can extract the coordinates with st_coordinates()
, but how can I join them back to the data to filter out the higher altitude?
Alternatively, is there any function in sf
that I could use to do the filter? I looked into the help but couldn't find anything relevant so far.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…