Here is the way:
## raw list to store Lines objects l <- vector("list", nrow(begin.coord)) library(sp) for (i in seq_along(l)) { l[[i]] <- Lines(list(Line(rbind(begin.coord[i, ], end.coord[i,]))), as.character(i)) } SpatialLines(l)
This makes a separate Lines object (each with a unique identifier) ββfor each pair, otherwise you may need one object?
And just for fun, first create a psppstpat object, and then apply the methods in maptools:
library(spatstat) p <- psp(begin.coord[,1], begin.coord[,2], end.coord[,1], end.coord[,2], owin(range(c(begin.coord[,1], end.coord[,1])), range(c(begin.coord[,2], end.coord[,2])))) library(maptools) as(p, "SpatialLines")
source share