Learn R Programming

data.tree (version 0.2.0-3)

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)

FromDataFrameNetwork(network)

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

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.

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

  • 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 as fields on the nodes

  • It must contain a single root

  • There are no cycles in the network

  • Node names are unique throughout the network (and not only per level, as required by data.tree)

Value

The root Node of the data.tree structure

See Also

as.data.frame.Node

Other as.Node: FromListExplicit, FromListSimple, as.Node.list; as.Node.dendrogram; as.Node.phylo; as.Node

Examples

Run this code
# NOT RUN {
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