make a dataset of 2 sets of coordinates, then using st_as_sf convert these to 2 geometry columns in r

# Create a dataset with 2 sets of coordinates
data <- data.frame(
  x = c(1, 2, 3),
  y = c(4, 5, 6),
  x2 = c(7, 8, 9),
  y2 = c(10, 11, 12)
)

# Convert to sf object with 2 geometry columns
library(sf)

coordinates <- st_as_sf(data, coords = c("x", "y"), 
                         coords2 = c("x2", "y2"), 
                         crs = st_crs("+proj=longlat +datum=WGS84"))

print(coordinates)
398 chars
17 lines

gistlibby LogSnag