Description Usage Arguments Value Examples
Put values into sensible categories
1 2 | recategorize(df, category_dictionary, encode_cols = NULL,
handle_duplicate_categories = "first")
|
df |
dataframe that contains the data we want to recategorize |
category_dictionary |
vector with names consisting of the keys to be looked up and values consisting of the category |
encode_cols |
which columns should be altered |
handle_duplicate_categories |
"first" takes first value in a certain category, "last" takes last value |
dataframe with encode_cols replaced with category columns (NAs are populated if no value in that category is found)
1 2 3 4 5 6 7 8 | my_mat <- matrix(c("obs1","obs2","obs3","a","a","k","d","o","e"),ncol = 3, nrow = 3)
my_mat <- as.data.frame(my_mat)
colnames(my_mat) <- c("name","1","2")
dict <- rep("consonant",26)
names(dict) <- letters
dict[c("a","e","i","o","u")] <- "vowel"
my_mat
recategorize(my_mat,encode_cols = c(2,3), category_dictionary = dict)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.