manyfold: Turn columns of a table into a tree like structure

Description Usage Arguments Value Author(s) See Also Examples

View source: R/cols2tree.R

Description

This function helps to illustrate the relationship between columns contained into a dataset. For example, imagine you have 3 columns containing country, region and city in your dataset. Checking that the right cities are in the right regions, and that the right regions are in the right countries, can be quite tedious (especially for a large dataset) when the data are shown as a table. It is much easier if the data are shown as a tree. This function helps you do that.

Usage

1
manyfold(.data, ..., count = TRUE, count_sep = ":", missing = "UNKNOWN")

Arguments

.data

the .data.frame or tibble to use

...

the columns to use to build the tree, quoted and separated by commas, starting with the broadest classifier on the left

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")

Value

an object of class Node on which many further actions are possible (see data.tree())

Author(s)

Alexandre Courtiol

See Also

data.tree()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
## 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"))

table

## Without specifying columns (takes them all in the order they come):
manyfold(table)

## With column specification:
manyfold(table, "country", "region", "city")

## Another way for displaying counts:
tree <- manyfold(table, "country", "region", "city", count = FALSE)
print(tree, "N")

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