sublast: Substitute last occurrence of a pattern in a string

View source: R/misc.R

sublastR Documentation

Substitute last occurrence of a pattern in a string

Description

Substitute last occurrence of a pattern in a string

Usage

sublast(pattern, replacement, x, ...)

Arguments

pattern

character string containing a regular expression whose whose last match in 'x' will be replaced

replacement

character string that is a replacement for the matched 'pattern' in 'x'

x

a character vector where matches are sought.

...

arguments passed to gsub.

Examples

string <- 'a_b_c_D'
sublast('_','__',string)
dd <- data.frame(id = 1:3, X_a_1 = 1:3, X_a_2 = 1:3, X_b_1 = 1:3, X_b_2 = 1:3)
dd
names(dd) <- sublast('_','__',names(dd))
tolong(dd, sep = '__')
tolong(dd, sep = '__') %>% tolong(sep = '_', idvar = 'id2', timevar = 'time2')


gmonette/spida2 documentation built on Aug. 20, 2023, 7:21 p.m.