clean_dvec | R Documentation |
Clean a vector of delimited strings
clean_dvec(vec, sep = ";")
vec |
A vector of delimited strings to clean |
sep |
String - delimiter used within each element of the vector to be cleaned |
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.
Vector - the cleaned input vector, with each element consisting of sorted, unique elements
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.