prettify: Replace/prettify matching words/terms in one vector by...

prettify_stringsR Documentation

Replace/prettify matching words/terms in one vector by another

Description

The function searches for x values, that occur in current and replaces them with entries in new. Useful for quick renaming/translation of survey column names and by using internal object .trans_df

Usage

prettify_strings(
  x,
  current = .trans_df$english,
  new = .trans_df$english_pretty
)

prettify_de(x)

prettify_en(x)

Arguments

x

A character vector (or factor) that should be renamed.

current

A vector of characters (possibly subset of x). Entries in x that match entries in current will be renamed according to entries in new.

new

A vector of characters that will replace entries in x which have matches in current.

Examples

library(coalitions)
library(dplyr)
# look at sample German federal election polls
surveys <- surveys_sample %>% tidyr::unnest("surveys") %>% group_by(pollster) %>% slice(1)
# prettify the polling agency names
prettify_strings(surveys$pollster)
prettify_en(surveys$pollster)
prettify_de(surveys$pollster)

adibender/coalitions documentation built on Aug. 22, 2022, 5:58 a.m.