
Last chance! 50% off unlimited learning
Sale ends in
data.frame
to a data.tree
structureConvert a data.frame
to a data.tree
structure
# 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)
The data.frame in the required format.
Any other argument implementations of this might need
Either "table" (if x is a data.frame in tree or table format) or "network"
The name of the column in x containing the path of the row
The delimiter used
Nested list of column names, determining on what node levels the attributes are written to.
If TRUE
, then NA's are treated as NULL and values will not be set on nodes
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.
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)
The root Node
of the data.tree
structure
Other as.Node: FromListExplicit
,
FromListSimple
, as.Node.list
;
as.Node.dendrogram
;
as.Node.phylo
; as.Node
# 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