In R I'm trying to create points using st_point() from package sf.
My input is a data.frame with one column being x-coordinate and another column y-coordinate:
# Code to generate input
library(sf)
N <- 10
df <- data.frame(x=rnorm(N),y=rnorm(N))
what I want to do is simply
# Code to generate examplar output
L <- list()
for (i in 1:N)
{
L[[i]] <- st_point(c(df$x[i],df$y[i]))
}
st_sfc(L)
But insted of looping I am trying to do it with mapply(.)
mapply(function(x,y) sum(c(x,y)),df$x,df$y)
mapply(function(x,y) st_point(c(x,y)),df$x,df$y)
which works for adding the columns but not for making spatial points.
My question is two fold: (1) Why does this use of mapply fail? (2) And what would be the efficient way to do it?