Add category for column.

df_add_category(x, col, values, new.value, factor.handling = "keep")

Arguments

x

[data.frame]
Data frame with at least one row and column.

col

[integer | string]
Column number or colmumn name.

values

[character]
Which values of the column col shall be unioned into the new category.

new.value

[any]
New category value.

factor.handling

[string]
Determines how to handle the case that col is a factor column. Option “drop” converts the factor into a character column. Option “keep” does the same, but after adding the new category, the factor property is reestablished. If the factor was ordered, the new category is placed last.

Value

Modified data frame.

See also

Other data frame helpers: df_add_constant_columns(), df_explode(), df_rows_to_list(), df_split_col()