longstring {esmtools}R Documentation

Calculate Longstring Value

Description

This function calculates the longstring value for a given vector of values.

Usage

longstring(x, tolerance = NULL)

Arguments

x

A vector of values for which the longstring value needs to be calculated.

tolerance

An optional parameter indicating the tolerance for considering consecutive values as equal (default is NULL).

Value

A dataframe containing the following information:

val

The longstring value(s) based on the most frequent value(s) or the unique value(s).

longstr

The length of the longest run of consecutive values.

avgstr

The average length of non-NA runs of consecutive values (not computed when tolerance is used).

Examples

df <- data.frame(
  rbind(
    c(1, 1, 2, 2, 2, 3, 3, 3, 3),
    c(1, 2, 3, 4, 4, 4, 4, 2, 6)
  )
)
# Example 1: Without tolerance
longstring(df)

# Example 2: With tolerance
longstring(df, tolerance = 1)


[Package esmtools version 1.0.1 Index]