Skip to contents

This returns a mutated act_tbl with a new column representing speed, in meters per second. See vignette("pace") for examples.

Usage

mutate_with_speed(df, method = c("2D", "3D"), lead = 0, lag = 1)

Arguments

df

An act_tbl object

method

If "2D" (default), ignores elevation. If "3D", includes elevation. "3D" is not often necessary, but for skiing activities is likely to yield a more accurate value.

lead

How far ahead to look for the "end" point.

lag

How far behind to look for the "start" point.

Value

That same act_tbl, but with a new speed column, in meters per second.

Details

The speed is determined by looking at the time difference between the current point and the previous point: hence, it is always NA for the first row in the data frame.

The lead and lag values are helpful to get "smoother" values, especially if the provided activity file has GPS errors in it.

Examples

example_gpx_file <- system.file(
  "extdata",
  "running_example.gpx.gz",
  package = "activatr"
)
example_act_tbl <- parse_gpx(example_gpx_file)
example_act_tbl_with_speed <- mutate_with_speed(example_act_tbl)
example_act_tbl_with_speed
#> # A tibble: 4,433 × 5
#>      lat   lon   ele time                speed
#>    <dbl> <dbl> <dbl> <dttm>              <dbl>
#>  1  37.8 -122.  17   2018-11-03 14:24:45 NA   
#>  2  37.8 -122.  16.8 2018-11-03 14:24:46  1.87
#>  3  37.8 -122.  17   2018-11-03 14:24:48  2.25
#>  4  37.8 -122.  17   2018-11-03 14:24:49  2.90
#>  5  37.8 -122.  17.2 2018-11-03 14:24:50  3.05
#>  6  37.8 -122.  17.6 2018-11-03 14:24:51  3.06
#>  7  37.8 -122.  17.4 2018-11-03 14:24:52  3.01
#>  8  37.8 -122.  17.4 2018-11-03 14:24:53  2.71
#>  9  37.8 -122.  17.4 2018-11-03 14:24:54  2.74
#> 10  37.8 -122.  17.4 2018-11-03 14:24:55  2.68
#> # ℹ 4,423 more rows