Calculate traveled distance from the naturalistic data
nds_calc_dist.Rd
nds_calc_dist
extracts traveled time from the naturalistic data.
Arguments
- data
A sf object with linestring geometry
- geom
The geometry column in the sf object
- by
A column name to group the results
- units
The desired distance unit ("meters", "kilometers")
Details
This function uses a sf object (nds_create_lines) as main
input and extracts its traveled distance, grouping the results by the
attributes of the desired variable (parameter by
). The distance
unit can be in "meters" (default) or "kilometers". The geom
parameter is used to identify the column that contains the geometry of the
sf object.
Examples
path <- system.file("extdata", package = "ndsbr")
nds_data <- nds_load_data("driver", path)
#> ℹ Using "','" as decimal and "'.'" as grouping mark. Use `read_delim()` for more control.
#> ℹ Using "','" as decimal and "'.'" as grouping mark. Use `read_delim()` for more control.
#> ℹ Using "','" as decimal and "'.'" as grouping mark. Use `read_delim()` for more control.
nds_lines <- nds_create_lines(nds_data, x = LONG, y = LAT)
nds_calc_dist(nds_lines, wkt_lines, DRIVER)
#> # A tibble: 3 × 2
#> DRIVER DIST
#> <chr> <dbl>
#> 1 A 22508.
#> 2 B 51529.
#> 3 C 37736.