Description Usage Arguments Value Examples
Compute the lengths and values of runs of equal values in a vector
1 2 |
x |
a numeric or character vector |
na.unique |
should every |
output |
what form of output |
Return value depends on output
.
data.frame
A data.frame with lengths and values columns
rle
An object of class "rle"
named vector
A vector of lengths with values as names
lengths
The lengths as a single vector
values
The values as a single vector
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | x <- c(NA, NA, 1, 2, 3, 3, NA, NA, NA, 2, 2, 2, NA, 1, 1, NA, NA)
rle2(x)
m <- matrix(c(
0.7, 0.2, 0.1,
0.2, 0.6, 0.2,
0.1, 0.2, 0.7
), 3, byrow=TRUE)
set.seed(1)
y <- LETTERS[markov_seq(n=100, m)]
rle2(y, out="named")
# Same result as rle
rle2(x, na.unique=TRUE, output="rle")
rle(x)
# inverse.rle works as long as output is "rle"
inverse.rle(rle2(x, output="rle"))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.