如何在R中将Tree + Cascade数据动态转换为Table Shape?

时间:2018-09-07 01:59:00

标签: r tree cascade

我需要一种动态级联数据集转换为普通表格数据集的方法。

方法的条件:

  1. 这是XLSX数据
  2. 第一列为空白(NA)
  3. 列尾的索引未知
  4. 在导入时为文件名创建列ID

用于生成级联数据集的代码

PhongMaterial { id: material; }

GeometryRenderer {
    id: renderer
    primitiveType: GeometryRenderer.LineLoop
    instanceCount: 1
    geometry: Geometry {
        attributes: [
            Attribute {
                name: defaultPositionAttributeName
                attributeType: Attribute.VertexAttribute
                vertexBaseType: Attribute.Float
                vertexSize: 3
                byteOffset: 0
                byteStride: 3 * 4
                count: 6
                buffer: Buffer {
                    type: Buffer.VertexBuffer
                    data: new Float32Array([
                                               // #1 triangle
                                               -0.9, -0.5, 0.0,
                                               -0.0, -0.5, 0.0,
                                               -0.45, 0.5, 0.0,
                                               // #2 triangle
                                               0.0, -0.5, 0.0,
                                               0.9, -0.5, 0.0,
                                               0.45, 0.5, 0.0,
                                           ])
                }
            }
        ]
    }
}

Entity {
    components: [
        renderer,
        material
    ]
}

您可以看到如下结构:

  • 列名称中的偶数代表“组”信息(奇数) 数据集索引的总列数)
  • 列名中的奇数代表“名称”信息(第一个 列为NA)(以数据集的总列数为偶数) 索引)
  • 一行仅包含一种类型的“组”信息

我天真的方法,但是每次导入新数据时都无法处理小巧的

DT <- data.table(X__1 = NA,
                 X__2 = c("A_GROUP","","","","","","","","","",""),
                 X__3 = c("JOHN","","","","","","","","","",""),
                 X__4 = c("","RED_TEAM","","GREEN_TEAM","","","","","","",""),
                 X__5 = c("","MARRY","TOM","PAUL","SAM","","","","",""),
                 X__6 = c("","","","","","A_LINE","","B_LINE","","C_LINE"),
                 X__7 = c("","","","","","JAMES","FAN","DEN","JOE","LAW","GEM"))

在这种情况下,我有7列,但有时数据包含9列 是不可预测的。(只有已确认的逻辑是数据的波动幅度为+-2 cols或更小)

有什么有效的方法可以解决那些矛盾吗?

0 个答案:

没有答案