df2hierchlist: Turn columns of a table into a hierarchical list

Description Usage Arguments Details Examples

View source: R/cols2list.R

Description

This function should not be called by the user. It is an internal function used by manyfold(). While manyfold() turns the hierarchical structure that exists between columns into a tree, the function df2hierchlist() turns the hierarchical structure that exists between columns into a list.

Usage

1
2
3
4
5
6
7
8
df2hierchlist(
  data,
  vars,
  listrec = list(),
  count = TRUE,
  count_sep = ":",
  missing = "UNKNOWN"
)

Arguments

data

the data.frame or tibble that contains the variables

vars

a vector of variable names

listrec

the list object in which to return the results

count

whether or not add the number of rows in the level names (default = TRUE)

count_sep

which separator to use when combining counts to level names (default = ":")

missing

how to call NA in the tree (default = "UNKNOWN")

Details

Because the function implement a recursive algorithm, we pass a list as an argument which is completed through the multiple recursive call of the function. For the same reason, we restrict the variable names to be quoted and confined to a vector, which helps with efficiency.

Examples

1
2
3
4
5
6
7
## Create a toy dataset:
table <- data.frame(country = c("France", "France", "France", "France",
"Spain", "Spain"), region = c("Herault", "Herault", "Aude", "Paris",
"Catalonia", "Andalusia"), city = c("Montpellier", "Montpellier", "Narbonne",
"Paris", "Barcelona", "Sevilla"))

df2hierchlist(table, c("country", "region", "city"))

courtiol/manyfold documentation built on March 7, 2020, 1:59 a.m.