Learn R Programming

trajr (version 1.0.0)

TrajSpeedIntervals: Calculate speed time intervals

Description

Calculates and returns a list of time intervals during which speed is slower and/or faster than specified values.

Usage

TrajSpeedIntervals(trj, fasterThan = NULL, slowerThan = NULL,
  interpolateTimes = TRUE)

Arguments

trj

Trajectory to be analysed.

fasterThan, slowerThan

If not NULL, intervals will cover time periods where speed exceeds/is lower than this value.

interpolateTimes

If TRUE, times will be linearly interpolated between frames.

Value

A data frame of class "TrajSpeedIntervals", each row is an interval, columns are:

startFrame

Indices of frames at the start of each interval.

stopFrame

Indices of frames at the end of each interval.

startTime

Time at the start of each interval.

stopTime

Time at the end of each interval

duration

Duration of each interval.

The data frame will also have non-standard attributes:

trajectory

Value of the trj argument.

slowerThan

Value of the slowerThan argument.

fasterThan

Value of the fasterThan argument.

derivs

Value returned by calling TrajDerivatives(trj).

See Also

TrajDerivatives for calculating trajectory speed and acceleration, plot.TrajSpeedIntervals for plotting speed over time with intervals highlighted.

Examples

Run this code
# NOT RUN {
# Plot speed, highlighting intervals where speed drops below 50 units/sec
set.seed(4)
trj <- TrajGenerate(200, random = TRUE)
smoothed <- TrajSmoothSG(trj, 3, 101)
intervals <- TrajSpeedIntervals(smoothed, slowerThan = 50, fasterThan = NULL)
plot(intervals)

# Report the duration of the maximum period of low speed
cat(sprintf("Duration of the longest low-speed interval was %g secs\n", max(intervals$duration)))

# }

Run the code above in your browser using DataLab