bind: Bind rows (features) of 'sftime' objects

bindR Documentation

Bind rows (features) of sftime objects

Description

Bind rows (features) of sftime objects

Bind columns (variables) of sftime objects

Usage

## S3 method for class 'sftime'
rbind(..., deparse.level = 1)

## S3 method for class 'sftime'
cbind(..., deparse.level = 1, sf_column_name = NULL, tc_column_name = NULL)

Arguments

...

Objects to bind; note that for the rbind and cbind methods, all objects have to be of class sftime; see dotsMethods.

deparse.level

An integer value; see rbind.

sf_column_name

Character value; specifies the active geometry column; passed on to st_sftime.

tc_column_name

Character value; specifies active time column; passed on to st_sftime.

Details

Both rbind and cbind have non-standard method dispatch (see cbind): the rbind or cbind method for sftime objects is only called when all arguments to be combined are of class sftime.

If you need to cbind e.g. a data.frame to an sf, use data.frame directly and use st_sftime on its result, or use bind_cols; see examples.

Value

rbind combines all sftime objects in ... row-wise and returns the combined sftime object.

cbind combines all sftime objects in ... column-wise and returns the combined sftime object. When called with multiple sftime objects warns about multiple time and geometry columns present when the time and geometry columns to use are not specified by using arguments tc_column_name and sf_column_name; see also st_sftime.

Examples

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

## Not run: 
st_time(x2) <- 1
rbind(x1, x2) # error because both tc1 and tc2 do not have the same class

## End(Not run)

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))   
  

sftime documentation built on Sept. 12, 2024, 6:18 a.m.