strrep {stringx}R Documentation

Duplicate Strings

Description

Concatenate a number of copies of each string.

Usage

strrep(x, times)

e1 %x*% e2

Arguments

e1, x

character vector (or an object coercible to) whose elements are to be duplicated

e2, times

numeric vector giving the number of times to repeat the corresponding strings

Details

Both arguments are recycled if necessary.

The `%x*%` operator mimics a vectorised version of Python's `*` for strings (str.__mul__).

Value

A character vector (in UTF-8).

`%x*%` and strrep preserve object attributes in a similar way as other Arithmetic operators.

Differences from Base R

Replacement for base strrep implemented with stri_dup.

Author(s)

Marek Gagolewski

See Also

The official online manual of stringx at https://stringx.gagolewski.com/

Related function(s): paste, sprintf

Examples

x <- structure(c(A="a", B=NA, C="c"), attrib1="value1")
x %x*% 3
x %x*% 1:3
"a" %x*% 1:3
stringx::strrep(x, 3)
base::strrep(x, 3)
y <- matrix(1:6, nrow=2, dimnames=list(c("A", "B"), NULL))
y %x*% 1:2
stringx::strrep(y, 1:2)
base::strrep(y, 1:2)


[Package stringx version 0.2.8 Index]