strutils {IRanges} | R Documentation |
Some low-level string utilities that operate on ordinary character vectors. For more advanced string manipulations, see the Biostrings package.
strsplitAsListOfIntegerVectors(x, sep=",")
x |
A character vector where each element is a string containing comma-separated decimal integer values. |
sep |
The value separator character. |
A list of integer vectors. The list is of the same length as the input.
strsplitAsListOfIntegerVectors
is similar to the
strsplitAsListOfIntegerVectors2
function shown in the
Examples section below, except that the former generally raises
an error where the latter would have inserted an NA
in
the returned object. More precisely:
strsplitAsListOfIntegerVectors
will print
an informative error message.
Finally, strsplitAsListOfIntegerVectors
is faster and uses
much less memory than strsplitAsListOfIntegerVectors2
.
H. Pages
x <- c("1116,0,-19", " +55291 , 2476,", "19184,4269,5659,6470,6721,7469,14601", "7778889, 426900, -4833,5659,6470,6721,7096", "19184 , -99999") y <- strsplitAsListOfIntegerVectors(x) y ## In normal situations (i.e. when the input is well-formed), ## strsplitAsListOfIntegerVectors() does actually the same as the ## function below but is faster and much more memory efficient: strsplitAsListOfIntegerVectors2 <- function(x, sep=",") { tmp <- strsplit(x, sep, fixed = TRUE) lapply(tmp, as.integer) } y2 <- strsplitAsListOfIntegerVectors2(x) stopifnot(identical(y, y2))