swap: Swap Two Patterns Simultaneously

Description Usage Arguments Value Examples

View source: R/swap.R

Description

Swap pattern x for pattern y and pattern y for pattern x in one fell swoop.

Usage

1
swap(x, pattern1, pattern2, ...)

Arguments

x

A text variable.

pattern1

Character string to be matched in the given character vector. This will be replaced by pattern2.

pattern2

Character string to be matched in the given character vector. This will be replaced by pattern1.

...

ignored.

Value

Returns a vector with patterns 1 & 2 swapped.

Examples

1
2
3
4
5
6
x <- c("hash_abbreviation", "hash_contractions", "hash_grade", "key_emoticons", 
    "key_power", "key_sentiment", "key_sentiment_nrc", "key_strength", 
    "key_syllable", "key_valence_shifters")

x
swap(x, 'hash_', 'key_')

Example output

 [1] "hash_abbreviation"    "hash_contractions"    "hash_grade"          
 [4] "key_emoticons"        "key_power"            "key_sentiment"       
 [7] "key_sentiment_nrc"    "key_strength"         "key_syllable"        
[10] "key_valence_shifters"
 [1] "key_abbreviation"      "key_contractions"      "key_grade"            
 [4] "hash_emoticons"        "hash_power"            "hash_sentiment"       
 [7] "hash_sentiment_nrc"    "hash_strength"         "hash_syllable"        
[10] "hash_valence_shifters"

textclean documentation built on May 2, 2019, 7:22 a.m.