Import packages
Creating sample datasets
LatLong <- c("40.841885, -73.856621",
"40.675026, -73.944855",
"40.726253, -73.806710",
"40.725375, -73.789845",
"40.845456, -73.876555")
Location <- c("Bronx", "Brooklyn",
"Manhattan", "Queens", "Staten Island")
geoData <- data.frame(LatLong, Location)
geoData
## LatLong Location
## 1 40.841885, -73.856621 Bronx
## 2 40.675026, -73.944855 Brooklyn
## 3 40.726253, -73.806710 Manhattan
## 4 40.725375, -73.789845 Queens
## 5 40.845456, -73.876555 Staten Island
LatLong <- c("42.652580 -73.756233",
"40.841885, -73.856621",
"42.880230, -78.878738",
"40.726253, -73.806710",
"40.845456, -73.876555")
Location <- c("Albany", "Bronx", "Buffalo",
"Manhattan", "Staten Island")
geoData2 <- data.frame(LatLong, Location)
geoData2
## LatLong Location
## 1 42.652580\t-73.756233 Albany
## 2 40.841885, -73.856621 Bronx
## 3 42.880230, -78.878738 Buffalo
## 4 40.726253, -73.806710 Manhattan
## 5 40.845456, -73.876555 Staten Island
Find common observations in two datasets
sameRows <- geoData %>% dplyr::inner_join(geoData2)
sameRows
## LatLong Location
## 1 40.841885, -73.856621 Bronx
## 2 40.726253, -73.806710 Manhattan
## 3 40.845456, -73.876555 Staten Island
Finding different observations in two datasets
Find observations in geoData that are not present in geoData2
fullGeo <- rbind(geoData, geoData2)
fullGeo[! duplicated(fullGeo, fromLast=TRUE) & seq(nrow(fullGeo)) <= nrow(geoData), ]
## LatLong Location
## 2 40.675026, -73.944855 Brooklyn
## 4 40.725375, -73.789845 Queens
Find observations in geoData2 that are not present in geoData
fullGeo <- rbind(geoData2, geoData)
fullGeo[! duplicated(fullGeo, fromLast=TRUE) & seq(nrow(fullGeo)) <= nrow(geoData2), ]
## LatLong Location
## 1 42.652580\t-73.756233 Albany
## 3 42.880230, -78.878738 Buffalo