Last chance! 50% off unlimited learning
Sale ends in
vec_identify_runs()
returns a vector of identifiers for the elements of
x
that indicate which run of repeated values they fall in. The number of
runs is also returned as an attribute, n
.
vec_identify_runs(x)
An integer vector with the same size as x
. A scalar integer attribute,
n
, is attached.
A vector.
Unlike base::rle()
, adjacent missing values are considered identical when
constructing runs. For example, vec_identify_runs(c(NA, NA))
will return
c(1, 1)
, not c(1, 2)
.
x <- c("a", "z", "z", "c", "a", "a")
vec_identify_runs(x)
y <- c(1, 1, 1, 2, 2, 3)
# With multiple columns, the runs are constructed rowwise
df <- data_frame(
x = x,
y = y
)
vec_identify_runs(df)
Run the code above in your browser using DataLab