
Find sibling codes within a hierarchical coding system
siblings.RdGiven a code from a hierarchical coding system (e.g. NOC or SOC), returns all other codes that share the same immediate parent. If the target code has no siblings at its own level (i.e. it is an "only child"), the function falls back to returning first cousins – codes at the same level that share the same grandparent instead.
Value
A character vector of sibling (or, failing that, first-cousin)
codes. Returns character(0) if target_code has no parent,
or if it has no parent and no grandparent from which cousins could be
derived.
Details
The search proceeds in two steps:
Siblings: codes sharing
target_code's immediate parent (excludingtarget_codeitself).Cousins: if no siblings are found, codes sharing a parent with
target_code's parent (i.e. sharing a grandparent), excluding the parent itself. Because these are children of the parent's own siblings, they are automatically at the same hierarchical level astarget_code.
The function does not climb beyond the grandparent level; if no
siblings or cousins are found there, it returns character(0).