strapply {gsubfn} | R Documentation |
Similar to "'gsubfn'"
except instead of performing substitutions
it returns the output of "'FUN'"
.
strapply(X, pattern, FUN = function(x, ...) x, ..., simplify = FALSE, USE.NAMES = FALSE)
X |
list or (atomic) vector of character strings to be used. |
pattern |
character string containing a regular expression (or
character string for "'fixed = TRUE')" to be matched in the
given character vector.
|
FUN |
the function to be applied to each element of "'X'" . |
... |
optional arguments to "'gsubfn'" . |
simplify |
logical; should the result be simplified to a vector or
matrix, as in "sapply" if possible? |
USE.NAMES |
logical; if "'TRUE'" and if "'X'" is character, use
"'X'" as
'names' for the result unless it had names already.
|
For each character string in "X"
the pattern is repeatedly
matched,
each such match along with
backreferences, if any, are passed to
the function "FUN"
and the output is returned as a list.
A list of character strings.
strapply("12;34:56,89,,12", "[0-9]+") # running window of 5 characters using 0-lookahead perl regexp x <- "abcdefghijkl" strapply(x, "(.)(?=(....))", paste0, backref = -2, perl = TRUE)[[1]] ## Not run: # convert to chron library(chron) x <- c("01/15/2005 23:32:45", "02/27/2005 01:22:30") x.chron <- strapply(x, "(../../....) (..:..:..)", chron, backref = -2) do.call(c, x.chron) ## End(Not run)