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 in r

# Creating a dataset with two sets of coordinates
df <- data.frame(
  lon1 = c(10, 20),
  lat1 = c(50, 60),
  lon2 = c(30, 40),
  lat2 = c(70, 80)
)

# Converting into spatial dataframe
library(sf)
coordinates <- c("lon1", "lat1")
geometry1 <- st_as_sf(df, coords = coordinates, crs = 4326)

coordinates <- c("lon2", "lat2")
geometry2 <- st_as_sf(df, coords = coordinates, crs = 4326)

# Display the spatial dataframes
print(geometry1)
print(geometry2)
453 chars
20 lines

gistlibby LogSnag