Displaying 2 results from an estimated 2 matches for "class_charact".
Did you mean:
class_character
2023 Mar 08
1
Augment base::replace(x, list, value) to allow list= to be a predicate?
...x, ...), values)
}
x <- c(1 ,2, NA, 3)
replace(x, is.na(x), 0)
[1] 1 2 0 3
replace(x, is.na, 0)
[1] 1 2 0 3
And for gsub(),
gsub <- new_generic("gsub", c("pattern", "replacement"),
function(pattern, replacement, x, ...) {
S7_dispatch()
})
method(gsub, list(class_character, class_character)) <- base::gsub
# My quick-and-dirty implementation as an example
method(gsub, list(class_character, class_function)) <-
function(pattern, replacement, x) {
m <- regexpr(pattern, x)
res <- replacement(regmatches(x, m))
mapply(gsub, pattern, as.character(res), x...
2023 Mar 07
1
Augment base::replace(x, list, value) to allow list= to be a predicate?
This could be extended to sub and gsub as well which gsubfn in the
gusbfn package already does:
library(gsubfn)
gsubfn("^..", toupper, c("abc", "xyz"))
## [1] "ABc" "XYz"
On Fri, Mar 3, 2023 at 7:22?PM Pavel Krivitsky <p.krivitsky at unsw.edu.au> wrote:
>
> Dear All,
>
> Currently, list= in base::replace(x, list, value)