Learn R Programming

stringr (version 1.5.1)

str_dup: Duplicate a string

Description

str_dup() duplicates the characters within a string, e.g. str_dup("xy", 3) returns "xyxyxy".

Usage

str_dup(string, times)

Value

A character vector the same length as string/times.

Arguments

string

Input vector. Either a character vector, or something coercible to one.

times

Number of times to duplicate each string.

Examples

Run this code
fruit <- c("apple", "pear", "banana")
str_dup(fruit, 2)
str_dup(fruit, 1:3)
str_c("ba", str_dup("na", 0:5))

Run the code above in your browser using DataLab