clean_dvec: Clean a vector of delimited strings

Description Usage Arguments Details Value Examples

View source: R/clean_dvec.R

Description

Clean a vector of delimited strings

Usage

1
clean_dvec(vec, sep = ";")

Arguments

vec

A vector of delimited strings to clean

sep

String - delimiter used within each element of the vector to be cleaned

Details

This function handles cases where delimited data is stored within each element of a vector. Such vectors are in a sense vectors of vectors, though each element is stored as a delimited string. In addition, these vectors resemble lists, which can store a sequence of vectors. The function will loop through each element of the input vector, check for the presence of a string containing the specified delimiter, split the element string apart by the delimiter, attempt to convert to numeric, and then sort the unique values contained within the split string.

Value

Vector - the cleaned input vector, with each element consisting of sorted, unique elements

Examples

1
2
3
4
5
df <- data.frame("mycol" = c("B; A; M", "D; O; G", "6; 2; 9; 10; 12"), 
                 stringsAsFactors = FALSE)
head(df$mycol)
df$mycol <- clean_dvec(df$mycol, sep = "; ")  
head(df$mycol)               

etnite/bwardr documentation built on April 14, 2021, 7:04 p.m.