将ctree的终端节点拆分规则存储到R中的数据框中

Store terminal node split rule of ctree into a dataframe in R

我有一个包含 6 个品牌的数据集 (Node1),在应用 ctree() 时,它被分成 2 个终端节点。 Node2 包含 4 个品牌 Node3 包含 2 个品牌。 我想提取每个终端节点的这些品牌并将它们存储在两个不同的数据框中。请建议如何做同样的事情。

这是我编写的代码:

    library("party")
    library(gridExtra)
    fileName <- "C\"
    data <- read.csv(paste(fileName, ".csv", sep=""), header=TRUE)
    pdd <- subset(data, select=c(col1,col2))

    pdd_ctree <- ctree(col1~col2, data=pdd, controls =  ctree_control(minsplit=30))

    print(pdd_ctree@tree$psplit$splitpoint[1:6])
    print(pdd_ctree@tree$psplit$splitpoint)

我得到的结果是:

    print(pdd_ctree@tree$psplit$splitpoint[1:6])
    [1] 1 0 1 1 0 1

    print(pdd_ctree@tree$psplit$splitpoint)
    [1] 1 0 1 1 0 1
    attr(,"levels")
    [1] "Brand01"            "Brand02"                "Brand03"          "Brand04"             
    [5] "Brand05" "Brand06"  

我的要求:

有 2 个数据帧 left.df 和 right.df

left.df 将包含 [Brand01,Brand03,Brand04,Brand06]

right.df 将包含 [Brand02,Brand05]

我想你只是想要:

lvls <- levels(pdd_ctree@tree$psplit$splitpoint)
left.df = lvls[pdd_ctree@tree$psplit$splitpoint == 1]
right.df = lvls[pdd_ctree@tree$psplit$splitpoint == 0]