View source: R/node_conversion_dataframe.R
as.data.frame.Node | R Documentation |
data.tree
structure to a data.frame
If a node field contains data of length > 1, then that is converted into a string in the data.frame.
## S3 method for class 'Node'
as.data.frame(
x,
row.names = NULL,
optional = FALSE,
...,
traversal = c("pre-order", "post-order", "in-order", "level", "ancestor"),
pruneFun = NULL,
filterFun = NULL,
format = FALSE,
inheritFromAncestors = FALSE
)
ToDataFrameTree(x, ..., pruneFun = NULL)
ToDataFrameTable(x, ..., pruneFun = NULL)
ToDataFrameNetwork(
x,
...,
direction = c("climb", "descend"),
pruneFun = NULL,
format = FALSE,
inheritFromAncestors = FALSE
)
ToDataFrameTypeCol(x, ..., type = "level", prefix = type, pruneFun = NULL)
x |
The root |
row.names |
|
optional |
logical. If |
... |
the attributes to be added as columns of the data.frame. See |
traversal |
any of 'pre-order' (the default), 'post-order', 'in-order', 'level', or 'ancestor'. See |
pruneFun |
allows providing a prune criteria, i.e. a function taking a |
filterFun |
a function taking a |
format |
if |
inheritFromAncestors |
if FALSE, and if the attribute is a field or a method, then only a |
direction |
when converting to a network, should the edges point from root to children ("climb") or from child to parent ("descend")? |
type |
when converting type columns, the |
prefix |
when converting type columns, the prefix used for the column names. Can be NULL to omit prefixes. |
ToDataFrameTree: a data.frame
, where each row represents a Node
in the tree or sub-tree
spanned by x
, possibly pruned according to pruneFun
.
ToDataFrameTable: a data.frame
, where each row represents a leaf Node
in the tree or sub-tree
spanned by x
, possibly pruned according to pruneFun
.
ToDataFrameNetwork: a data.frame
, where each row represents a Node
in the tree or sub-tree
spanned by x
, possibly pruned according to pruneFun
. The first column is called 'from', while the
second is called 'to', describing the parent to child edge (for direction "climb") or the child to parent edge (for direction "descend").
If AreNamesUnique
is TRUE, then the Network is
based on the Node$name
, otherwise on the Node$pathString
ToDataFrameTypeCol: a data.frame
in table format (i.e. where each row represents a leaf in the tree or sub-tree
spanned by x
), possibly pruned according to pruneFun
. In addition to ...
, each distinct
type
is output to a column.
data(acme)
acme$attributesAll
as.data.frame(acme, row.names = NULL, optional = FALSE, "cost", "p")
ToDataFrameTree(acme, "cost", "p")
ToDataFrameNetwork(acme, "cost", "p", direction = "climb")
ToDataFrameTable(acme, "cost", "p")
ToDataFrameTypeCol(acme)
#use the pruneFun:
acme$Do(function(x) x$totalCost <- Aggregate(x, "cost", sum), traversal = "post-order")
ToDataFrameTree(acme, "totalCost", pruneFun = function(x) x$totalCost > 300000)
#inherit
acme$Set(floor = c(1, 2, 3), filterFun = function(x) x$level == 2)
as.data.frame(acme, row.names = NULL, optional = FALSE, "floor", inheritFromAncestors = FALSE)
as.data.frame(acme, row.names = NULL, optional = FALSE, "floor", inheritFromAncestors = TRUE)
#using a function as an attribute:
acme$Accounting$Head <- "Mrs. Numright"
acme$Research$Head <- "Mr. Stein"
acme$IT$Head <- "Mr. Squarehead"
ToDataFrameTable(acme, department = function(x) x$parent$name, "name", "Head", "cost")
#complex TypeCol
acme$IT$Outsource$AddChild("India")
acme$IT$Outsource$AddChild("Poland")
acme$Set(type = c('company', 'department', 'project', 'project', 'department',
'project', 'project', 'department', 'program', 'project',
'project', 'project', 'project'
)
)
print(acme, 'type')
ToDataFrameTypeCol(acme, type = 'type')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.