create a dataset with 2 sets of coordinates in latitude and longitude in 4 columns. then using st_as_sf convert these into 2 different geometry columns, and then join them together in r
library(sf)
library(dplyr)
# Create a data frame with 2 sets of coordinatesdata <- data.frame(
id = c(1, 2),
lon1 = c(-122.4194, -118.2437),
lat1 = c(37.7749, 34.0522),
lon2 = c(-117.1611, -121.9467),
lat2 = c(32.7157, 36.7783)
)
# Use st_as_sf to convert coordinates into geometry columnspoints1 <- st_as_sf(data, coords = c("lon1", "lat1"), crs = 4326)
points2 <- st_as_sf(data, coords = c("lon2", "lat2"), crs = 4326)
# Join the two datasetsjoined_points <- left_join(points1, points2, by = "id")