Learn R Programming

data.tree (version 1.1.0)

as.Node.data.frame: Convert a data.frame to a data.tree structure

Description

Convert a data.frame to a data.tree structure

Usage

# S3 method for data.frame
as.Node(
  x,
  ...,
  mode = c("table", "network"),
  pathName = "pathString",
  pathDelimiter = "/",
  colLevels = NULL,
  na.rm = TRUE
)

FromDataFrameTable( table, pathName = "pathString", pathDelimiter = "/", colLevels = NULL, na.rm = TRUE, check = c("check", "no-warn", "no-check") )

FromDataFrameNetwork(network, check = c("check", "no-warn", "no-check"))

Value

The root Node of the data.tree structure

Arguments

x

The data.frame in the required format.

...

Any other argument implementations of this might need

mode

Either "table" (if x is a data.frame in tree or table format) or "network"

pathName

The name of the column in x containing the path of the row

pathDelimiter

The delimiter used to separate nodes in pathName

colLevels

Nested list of column names, determining on what node levels the attributes are written to.

na.rm

If TRUE, then NA's are treated as NULL and values will not be set on nodes

table

a data.frame in table or tree format, i.e. having a row for each leaf (and optionally for additional nodes). There should be a column called pathName, separated by pathDelimiter, describing the path of each row.

check

Either

  • "check": if the name conformance should be checked and warnings should be printed in case of non-conformance (the default)

  • "no-warn": if the name conformance should be checked, but no warnings should be printed in case of non-conformance (if you expect non-conformance)

  • "no-check" or FALSE: if the name conformance should not be checked; use this if performance is critical. However, in case of non-conformance, expect cryptic follow-up errors

network

A data.frame in network format, i.e. it must adhere to the following requirements:

  • It must contain as many rows as there are nodes (excluding the root, there is no row for the root)

  • Its first and second columns contain the network relationships. This can be either climbing (from parent to children) or descending (from child to parent)

  • Its subsequent columns contain the attributes to be set on the nodes

  • It must contain a single root

  • There are no cycles in the network

See Also

as.data.frame.Node

Other as.Node: as.Node.dendrogram(), as.Node.list(), as.Node.phylo(), as.Node.rpart(), as.Node()

Examples

Run this code
data(acme)

#Tree
x <- ToDataFrameTree(acme, "pathString", "p", "cost")
x
xN <- as.Node(x)
print(xN, "p", "cost")

#Table
x <- ToDataFrameTable(acme, "pathString", "p", "cost")
x
xN <- FromDataFrameTable(x)
print(xN, "p", "cost")

#More complex Table structure, using colLevels
acme$Set(floor = c(1, 2, 3),  filterFun = function(x) x$level == 2)
x <- ToDataFrameTable(acme, "pathString", "floor", "p", "cost")
x
xN <- FromDataFrameTable(x, colLevels = list(NULL, "floor", c("p", "cost")), na.rm = TRUE)
print(xN, "floor", "p", "cost")

#Network
x <- ToDataFrameNetwork(acme, "p", "cost", direction = "climb")
x
xN <- FromDataFrameNetwork(x)
print(xN, "p", "cost")

Run the code above in your browser using DataLab