purge_string {trustmebro}R Documentation

Purge strings in a data frame

Description

Clean specified character columns in a data frame or tibble by removing non-alphanumeric characters, replacing them with a specified character (default is "#"). Also replaces NA values and allows for additional characters to keep in the cleaned strings. The resulting strings are converted to uppercase.

Usage

purge_string(data, ..., replacement = "#", keep = "")

Arguments

data

A data frame or tibble containing columns to be cleaned.

...

Variables to clean. If none are provided, all character columns will be processed.

replacement

A character string used to replace unwanted characters and empty strings. Default is "#".

keep

A character string containing any additional characters that should be retained in the cleaned strings.

Value

A data frame or tibble with the specified character columns cleaned and modified as per the given parameters.

Examples

# Example data
print(sailor_students)

# Clean all character columns, replacing unwanted characters with "#", retaining "-" 
sailor_students_cleaned <- 
purge_string(sailor_students, sgic, school, class, gender, keep = "-")

# Tibble with cleaned 'sgic', 'school', 'class' and 'gender' columns
print(sailor_students_cleaned)

[Package trustmebro version 1.0.0 Index]