Skip to contents

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)
#>   val longstr avg_longstr
#> 1   3       4           3
#> 2   4       4         1.5

# Example 2: With tolerance
longstring(df, tolerance = 1)
#>   val longstr avg_longstr
#> 1   2       7        4.11
#> 2   3       6        2.44