Description Usage Arguments Details See Also Examples
Split a vector into a list of runs, such that each entry in
the output list is a set of runs encountered. This function
accepts two forms of inputs: either a vector where each
element of the vector is of length 1 (e.g. c("A",
"A", "C", "T")
), or a vector of length 1 interpretted as a
long string (e.g. "AAAACCAGGGACGCCGCGGTTGG"
).
1 | split_runs(x)
|
x |
A numeric or character vector. |
Factors will be coerced to character before splitting.
rle
, for a similar function with different
output.
1 2 3 4 5 6 7 | x <- rbinom( 100, 2, 0.5 )
stopifnot( all( x == unlist( split_runs(x) ) ) )
stopifnot( all( as.character(x) == unlist( split_runs( as.character(x) ) ) ) )
y <- paste( collapse="", sample( LETTERS[1:5], 1E5, replace=TRUE ) )
stopifnot( y == paste( collapse="", split_runs(y) ) )
z <- replicate( 25, paste( collapse="", sample( LETTERS[1:5], 1E3, replace=TRUE ) ) )
system.time( lapply(z, split_runs) )
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.