g1 <- st_sfc(st_point(1:2))
x1 <- st_sftime(a = 3, geometry = g1, time = Sys.time())
g2 <- st_sfc(st_point(c(4, 6)))
x2 <- st_sftime(a = 4, geometry = g2, time = Sys.time())
rbind(x1, x2) # works because both tc1 and tc2 have the same class
if (FALSE) {
st_time(x2) <- 1
rbind(x1, x2) # error because both tc1 and tc2 do not have the same class
}
cbind(x1, x2)
if (require(dplyr)) {
# returns a data frame because names of sf and time column are modified:
dplyr::bind_cols(x1, x2)
# returns an sf object because the name of the time column is modified:
dplyr::bind_cols(x1, x2 %>% sf::st_drop_geometry())
# returns an sftime object because names of sf and time column are both
# preserved:
dplyr::bind_cols(x1, x2 %>% st_drop_time() %>% sf::st_drop_geometry())
}
df <- data.frame(x = 3)
st_sftime(data.frame(x1, df))
Run the code above in your browser using DataLab