Index zones.

Share:

Description

Generate a vector of zone "levels" from an input vector and defined boundaries.

Usage

1
zone_index(x, zbounds)

Arguments

x

numeric; values to be "zoned".

zbounds

numeric; values for zone boundaries.

Value

a numeric vector of zone values of the same length as x. The number of zone levels will be length(zbounds) + 1.

Examples

1
2
3
4
5
6
7
8
data(ridedata)

## Best used to append to existing data.
ridedata$zone <- zone_index(ridedata$power.W, c(100, 200, 300))

## How much distance was covered in each zone?
ridedata$delta.dist <- c(0, diff(ridedata$distance.km))
with(ridedata, tapply(delta.dist, zone, sum, na.rm = TRUE))  # Km.