如何 select area/polygon (lat, long) inside data frame R
How select area/polygon (lat, long) inside data frame R
我有一个包含超过 90.0000 个位置(纬度和经度)和潜水深度的数据框,我想要 2 个东西。
#I wrote this example above to who gonna help can try at your R program.
df = data.table(dive = c(10, 15, 20, 50, 70, 80, 90, 40, 100, 40, 40,
50, 67, 45, 70, 30),
lat = c(-23, -24, -25, -26, -27, -28, -29, -30, -32,
-33, -34, -35, -36, -37, -38, -39),
lon = c(-44, -43, -42, -41, -40, -39, -38, -35, -30,
-28, -25, -23, -20, -19, -18, -15))
#the class of all of this is numeric
-第一个
为了让你更好地理解,我有这张地图,圆圈是给定位置的潜水深度:
我有潜水深度,我想要 select 一个特定区域(纬度 = -36,纬度 = - 27,经度 = -27 和经度 = -40)。
我想要 select 这个区域内的蓝色潜水深度在数据框:
- 第二
现在,我需要 select 绿色的逆区域:
:
我尝试了什么
我试图对select“蓝色”区域执行此操作:
df2<-df[df$lat <= -36 & df$lat >= -27 & df$lon >= -27 & df$lon <= -40]
#this return the data frame with no variables and with all locations
#And I tried inserting a comma at the end
df2<-df[df$lat <= -36 & df$lat >= -27 & df$lon >= -27 & df$lon <= -40,]
#this return the data frame with no observations
有人知道怎么做吗?
谢谢!
您可以使用:
blue_area <- subset(df, lat >= -36 & lat <= -27 & lon <= -27 & lon >= -40)
green_area <- dplyr::anti_join(df, blue_area)
我有一个包含超过 90.0000 个位置(纬度和经度)和潜水深度的数据框,我想要 2 个东西。
#I wrote this example above to who gonna help can try at your R program.
df = data.table(dive = c(10, 15, 20, 50, 70, 80, 90, 40, 100, 40, 40,
50, 67, 45, 70, 30),
lat = c(-23, -24, -25, -26, -27, -28, -29, -30, -32,
-33, -34, -35, -36, -37, -38, -39),
lon = c(-44, -43, -42, -41, -40, -39, -38, -35, -30,
-28, -25, -23, -20, -19, -18, -15))
#the class of all of this is numeric
-第一个
为了让你更好地理解,我有这张地图,圆圈是给定位置的潜水深度:
我有潜水深度,我想要 select 一个特定区域(纬度 = -36,纬度 = - 27,经度 = -27 和经度 = -40)。
我想要 select 这个区域内的蓝色潜水深度在数据框:
- 第二
现在,我需要 select 绿色的逆区域:
我尝试了什么
我试图对select“蓝色”区域执行此操作:
df2<-df[df$lat <= -36 & df$lat >= -27 & df$lon >= -27 & df$lon <= -40]
#this return the data frame with no variables and with all locations
#And I tried inserting a comma at the end
df2<-df[df$lat <= -36 & df$lat >= -27 & df$lon >= -27 & df$lon <= -40,]
#this return the data frame with no observations
有人知道怎么做吗? 谢谢!
您可以使用:
blue_area <- subset(df, lat >= -36 & lat <= -27 & lon <= -27 & lon >= -40)
green_area <- dplyr::anti_join(df, blue_area)