Learn R Programming

taRifx (version 1.0.6.2)

middle.group: Return a vector containing the locations of the middle of every group in a vector, either as a numerical index or as a TRUE/FALSE boolean.

Description

This function uses run length encoding to determine the middle of every group of repeated values within a larger vector.

Usage

middle.group(vec, type = "tf")

Arguments

vec

Any vector which you want to know the middle of.

type

Either "tf" to return a boolean or "loc" to return a set of numerical locations.

Value

If type=="tf": Boolean of length length(vec) containing TRUE if the middle of a grouping and FALSE if not. If type=="loc": Vector of length equal to the number of groups in vec, containing locations of the group centers. Ties (for groups of even length) are broken by rounding up.

Examples

Run this code
# NOT RUN {
test <- c(1,2,2,2,2,2,2,2,2,2,1)
middle.group(test)
middle.group(test,type="loc")
# }

Run the code above in your browser using DataLab