访问data.tree中的节点-R

时间:2018-07-03 11:28:59

标签: r dataframe tree treeview

我在这里有两个问题,两者大致相同。

这是我第一个问题的样本数据,

ngOnInit() {
    var self = this;
    $('.sign-up-label').on('show.bs.modal', function (e) {
      self.isCaptcha = true;
    })

我正在尝试以编程方式添加子项。

dput(data_samp)
structure(list(name = c("date", "totals"), type = c("STRING", 
"RECORD"), fields = list(NULL, structure(list(mode = c("NULLABLE", 
"NULLABLE", "NULLABLE", "NULLABLE", "NULLABLE", "NULLABLE", "NULLABLE", 
"NULLABLE", "NULLABLE", "NULLABLE", "NULLABLE", "NULLABLE", "NULLABLE"
), name = c("visits", "hits", "pageviews", "timeOnSite", "bounces", 
"transactions", "transactionRevenue", "newVisits", "screenviews", 
"uniqueScreenviews", "timeOnScreen", "totalTransactionRevenue", 
"sessionQualityDim"), type = c("INTEGER", "INTEGER", "INTEGER", 
"INTEGER", "INTEGER", "INTEGER", "INTEGER", "INTEGER", "INTEGER", 
"INTEGER", "INTEGER", "INTEGER", "INTEGER")), .Names = c("mode", 
"name", "type"), class = "data.frame", row.names = c(NA, 13L)))), class = "data.frame", row.names = c(NA, 
-2L), .Names = c("name", "type", "fields"))

但是继续获取​​-library(data.tree) construct_tree <- function(x) { gq <- Node$new("sessions") for(i in 1:nrow(x)) { if(x[i,c("type")] != 'RECORD') gq$AddChild(x[i,c("name")]) else{ y <- as.data.frame(x[i,c('fields')]) for(j in 1:nrow(y)){ parent <- x[i,"name"] parent$AddChild(y[j,c("name")]) } } } gq } 。谁能帮我使用父变量作为节点名称并在其下添加子代吗?

第二种方法,我试图使用FindNode获取节点名称并在其下添加子代,

construct_tree <-function(x){

Error: $ operator is invalid for atomic vectors

但是这种方法的问题是FindNode需要唯一的节点名称,而我的实际数据在不同级别具有相同的节点名称。因此,它每次都获取不同的节点。我有什么方法可以搜索特定级别的节点?

谢谢。

0 个答案:

没有答案