Learn R Programming

gsubfn (version 0.1-3)

strapply: Apply a function over a string or strings.

Description

Similar to "'gsubfn'" except instead of performing substitutions it returns the output of "'FUN'".

Usage

strapply(X, pattern, FUN = function(x, ...) x, ..., 
   simplify = FALSE, USE.NAMES = FALSE)

Arguments

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.

Value

  • A list of character strings.

Details

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.

See Also

See Also as gsubfn, sapply

Examples

Run this code
strapply("12;34:56,89,,12", "[0-9]+")

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

Run the code above in your browser using DataLab