Questions tagged [gsubfn]

An R library enabling regex-based string replacement that allows a function as a replacement argument. The whole match and its capturing groups can be passed to that function and the match can be further manipulated inside the function (like incrementing matched numbers, replace certain patterns only inside another pattern, etc.)

gsubfn is like gsub but can take a replacement function or certain other objects instead of the replacement string. Matches and back references are input to the replacement function and replaced by the function output. gsubfn can be used to split strings based on content rather than delimiters and for quasi-perl-style string interpolation. The package also has facilities for translating formulas to functions and allowing such formulas in function calls instead of functions. This can be used with R functions such as apply, sapply, lapply, optim, integrate, xyplot, Filter and any other function that expects another function as an input argument or functions like cat or sql calls that may involve strings where substitution is desirable.

16 questions
0
votes
1 answer

Retrieving a partial string from a larger string in R

I have a data set where every observation has an ID value describing multiple things, for example AE1 indicates site A, type E, observation 1. I am trying to generate a column just for type so in the above example I am trying to filter out the E…
1
2