Description Usage Arguments Details Examples
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.
1 2 3 4 5 6 7 8 | df2hierchlist(
data,
vars,
listrec = list(),
count = TRUE,
count_sep = ":",
missing = "UNKNOWN"
)
|
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") |
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.
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"))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.