如何从数据框创建结构递归列表?

时间:2019-05-06 06:08:11

标签: r

我有一个数据框,我想使用结构函数将其转换为列表列表,并使用列添加更多属性

df <- data.frame(
        parent = c(0, 0 , 1, 1, 0),
        child = c(0, 1, 2, 3, 13),
        text = c("All", "Project Financing", "Combined Lines of Financing",
          "Equity", "Special Assistance"),
        stdisabled = c(FALSE, TRUE, FALSE, FALSE, FALSE),
        sticon = c("folder", "folder", "file", "file", "folder"),
        stopened = c(TRUE, FALSE, TRUE, TRUE, FALSE))

我希望这样:

list(All= structure(list(
     "Project Financing" = structure(list(
     "Combined Lines of Financing" = structure("", 
      stdisabled = FALSE, sticon = "file", stopened = TRUE), 
     "Equity" = structure("", stdisabled = FALSE, sticon = "file", 
                         stopened = TRUE)), stdisabled = TRUE, 
                         sticon = "folder", stopened = FALSE),
     "Special Assistance" = structure("", stdisabled = FALSE, 
     sticon = "folder", stopened = TRUE)), 
     stdisabled = FALSE, sticon = "folder", stopened = TRUE))

0 个答案:

没有答案