split_runs: Split by Runs

Description Usage Arguments Details See Also Examples

View source: R/split_runs.R

Description

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").

Usage

1

Arguments

x

A numeric or character vector.

Details

Factors will be coerced to character before splitting.

See Also

rle, for a similar function with different output.

Examples

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) )

Kmisc documentation built on May 29, 2017, 1:43 p.m.

Related to split_runs in Kmisc...