Skip to contents

This function renumbers a sequence, which is helpful if "gaps" appear in the sequence. For example, consider the sequence {1, 1, 3, 1, 8, 8, 8}. This function will renumber the sequence {1, 1, 2, 1, 3, 3, 3}. NAs are ignored.

Usage

renumSeq(x)

Arguments

x

Numerical or character vector.

Value

A vector.

See also

Examples


x <- c(1, 1, 3, 1, 8, 8, 8)
renumSeq(x)
#> [1] 1 1 2 1 3 3 3

y <- c(1, 1, 3, 1, 8, NA, 8, 8)
renumSeq(y)
#> [1] 1 1 2 1 3 3 3

z <- c('c', 'c', 'b', 'a', 'w', 'a')
renumSeq(z)
#> [1] 3 3 2 1 4 1