recategorize: Recategorize

Description Usage Arguments Value Examples

View source: R/recategorize.R

Description

Put values into sensible categories

Usage

1
2
recategorize(df, category_dictionary, encode_cols = NULL,
  handle_duplicate_categories = "first")

Arguments

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

Value

dataframe with encode_cols replaced with category columns (NAs are populated if no value in that category is found)

Examples

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)

jveech/recolumnize documentation built on Dec. 11, 2019, 2:05 a.m.