Learn R Programming

iNZightTools (version 2.0.1)

add_suffix: Add suffix to string

Description

When creating new variables or modifying the data set, we often add a suffix added to distinguish the new name from the original one. However, if the same action is performed twice (for example, filtering a data set), the suffix is duplicated (data.filtered.filtered). This function averts this by adding the suffix if it doesn't exist, and otherwise appending a counter (data.filtered2).

Usage

add_suffix(name, suffix)

Value

character vector of names with suffix appended

Arguments

name

a character vector containing (original) names

suffix

the suffix to add, a length-one character vector

Examples

Run this code
add_suffix("data", "filtered")
add_suffix(c("data.filtered", "data.filtered.reshaped"), "filtered")

Run the code above in your browser using DataLab