Skip to contents

Reorder Tiers in Knowledge

Usage

reorder_tiers(kn, order, by_index = FALSE)

Arguments

kn

A Knowledge object.

order

A vector that lists every tier exactly once, either by label (default) or by numeric index (by_index = TRUE). Be careful if you have numeric tier labels.

by_index

If TRUE, treat order as the positions instead of labels. Defaults to FALSE.

Value

The same Knowledge object with tiers rearranged.

Examples

# Move one tier relative to another
data(tpc_example)

kn <- knowledge(
  head(tpc_example),
  tier(
    child ~ starts_with("child"),
    youth ~ starts_with("youth"),
    oldage ~ starts_with("old")
  )
)

kn <- reorder_tiers(kn, c("youth", "child", "oldage"))
print(kn)
#> <Knowledge: 3 tiers | 6 vars>
#>   tier(youth): youth_x3, youth_x4
#>   tier(child): child_x1, child_x2
#>   tier(oldage): oldage_x5, oldage_x6