str_arithmetic {tinycodet} | R Documentation |
String arithmetic operators.
The x %s+% y
operator is exported from 'stringi',
and concatenates character vectors x
and y
.
The x %s-% p
operator removes character/pattern defined in p
from x
.
The x %s*% n
operator is exported from 'stringi',
and duplicates each string in x
n
times, and concatenates the results.
The x %s/% p
operator counts how often regular expression or character pattern p
occurs in each element of x
.
The x %s//% brk
operator counts how often the text boundary specified in list brk
occurs in each element of x
.
The e1 %s$% e2
operator is exported from 'stringi',
and provides access to stri_sprintf in the form of an infix operator.
x %s-% p
x %s/% p
x %s//% brk
x |
a string or character vector. |
p |
either a list with 'stringi' arguments (see s_regex),
or else a character vector of the same length as |
brk |
a list with arguments to be send to stri_count_boundaries. |
The %s+%
, %s-%
, and %s*%
operators
return a character vector of the same length as x
.
The %s/%
and %s//%
both return an integer vector of the same length as x
.
The %s$%
operator returns a character vector.
x <- c(paste0(letters[1:13], collapse=""), paste0(letters[14:26], collapse=""))
print(x)
y <- c("a", "b")
p <- rep("a|e|i|o|u", 2) # same as p <- list(regex=rep("a|e|i|o|u", 2))
n <- c(3, 2)
x %s+% y # =paste0(x,y)
x %s-% p # remove all vowels from x
x %s*% n
x %s/% p # count how often vowels appear in each string of vector x.
test <- c(
paste0("The\u00a0above-mentioned features are very useful. ",
"Spam, spam, eggs, bacon, and spam. 123 456 789"),
"good morning, good evening, and good night"
)
test %s//% list(type = "character")
#############################################################################
x <- c(paste0(letters[1:13], collapse=""), paste0(letters[14:26], collapse=""))
print(x)
y <- "a"
# pattern that ignores case:
p <- list(regex=rep("A|E|I|O|U", 2), case_insensitive = TRUE)
n <- c(2, 3)
x %s+% y # =paste0(x,y)
x %s-% p # remove all vowels from x
x %s*% n
x %s/% p # count how often vowels appears in each string of vector x.