set_keys: Set keys for a rulelist

View source: R/rulelist.R

set_keysR Documentation

Set keys for a rulelist

Description

'keys' are a set of column(s) which identify a group of rules in a rulelist. Methods like predict, augment produce output per key combination.

Usage

set_keys(x, keys, reset = FALSE)

Arguments

x

A rulelist

keys

(character vector or NULL)

reset

(flag) Whether to reset the keys to sequential numbers starting with 1 when keys is set to NULL

Details

A new rulelist is returned with attr keys is modified. The input rulelist object is unaltered.

Value

A rulelist object

See Also

rulelist, tidy, augment, predict, calculate, prune, reorder

Other Core Rulelist Utility: set_validation_data()

Examples

model_c5 = C50::C5.0(Attrition ~., data = modeldata::attrition, rules = TRUE)
tidy_c5 = tidy(model_c5)
tidy_c5 # keys are: "trial_nbr"

tidy_c5[["rule_nbr"]] = 1:nrow(tidy_c5)
new_tidy_c5 = set_keys(tidy_c5, NULL) # remove all keys
new_tidy_c5

new_2_tidy_c5 = set_keys(new_tidy_c5, "trial_nbr") # set "trial_nbr" as key
new_2_tidy_c5

# Note that `tidy_c5` and `new_tidy_c5` are not altered.
tidy_c5
new_tidy_c5


tidyrules documentation built on June 30, 2024, 1:07 a.m.