R-如何通过动态分组列值从现有数据帧列表列值创建新数据帧

时间:2017-11-12 06:40:00

标签: r algorithm

我是R编程语言的新手,我正在通过学​​习在线文档使用统计R编程语言来完成我的第一个项目。但是我打动了一些与我的需求相关的地方。请帮助我实现。

我的数据框。

 CTerms      AUHistory                                                         VenDetails                                Purchaseitem     

    Valid       list(DID = c("200","300"),Dprice = c("$652.94","$252.04"))   list(`cust#`="44",CADD ="SHi,US")     list(Group= "ship",Email ="ga",Details = list(list(PDesc ="D,C",Bsku ="47")))

    Test        list(DID = c("400","20"),Dprice = c("$252.04", "$252.04"))   list(`cust#`= "45",CADD ="SHi,US")    list(Group = "ship",Email ="ga",Details =list(list(PDesc = "D,C,S",Bsku ="47")))

    Invalid     list(DID = c("200","200"),Dprice = c("$652.94.04","$27.4"))  list(`cust#` ="44",CADD ="SHi,US")    list(Group = "ship",Email ="ga",Details =list(list(PDesc = "D,T",Bsku ="47")))

我的预期数据框。

我通过对cust#进行分组来获得数据框架。

`cust#`   ColumnHeader      ColValues   

    44       CTerms          list(Value = "Valid", count="1", list(Value="Invalid",count = "1"))                              
    44       DID             list(Value = "200", count=3,list(Value="300",count="1")
    44       Dprice          list(Value ="$652.94",count="1",list(Value="$252.04",count="1"),list(Value="$652.94.04", count="1"),list(Value="$27.4",count ="1"))
    44       CADD            list(Value = "SHi", count="2", list(Value="US",count = "2"))
    44       Group           list(Value = "ship", count="2")
    44       Email           list(Value = "ga", count="2")
    44       PDesc           list(Value ="D",count="2",list(Value="C",count="1"),list(Value="T", count="1"))
    44       Bsku            list(Value = "47", count="2")
    45       CTerms          list(Value = "Test", count="1")
    45       DID             list(Value = "400", count=1,list(Value="20",count="1")
    45       Dprice          list(Value = "$252.04", count=2)
    45       CADD            list(Value = "SHi", count=1,list(Value="US",count="1")
    45       Group           list(Value = "ship", count="1")
    45       Email           list(Value = "ga", count="1")
    45       PDesc           list(Value ="D",count="1",list(Value="C",count="1"),list(Value="S", count="1"))
    45       Bsku            list(Value = "47", count="1")

dput

structure(list(CTerms = c("Valid", "Test", "Invalid"), AUHistory = list(
    structure(list(DID = c("200", "300"), Dprice = c("$652.94", 
    "$252.04")), .Names = c("DID", "Dprice"), class = "data.frame", row.names = 1:2), 
    structure(list(DID = c("400", "20"), Dprice = c("$252.04", 
    "$252.04")), .Names = c("DID", "Dprice"), class = "data.frame", row.names = 1:2), 
    structure(list(DID = c("200", "200"), Dprice = c("$652.94.04", 
    "$27.4")), .Names = c("DID", "Dprice"), class = "data.frame", row.names = 1:2)), 
    VenDetails = list(structure(list(`cust#` = "44", CADD = "SHi, US"), .Names = c("cust#", 
    "CADD"), class = "data.frame", row.names = 1L), structure(list(
        `cust#` = "45", CADD = "SHi, US"), .Names = c("cust#", 
    "CADD"), class = "data.frame", row.names = 1L), structure(list(
        `cust#` = "44", CADD = "SHi, US"), .Names = c("cust#", 
    "CADD"), class = "data.frame", row.names = 1L)), Purchaseitem = list(
        structure(list(Group = "ship", Email = "ga", Details = list(
            structure(list(PDesc = "D, C", Bsku = "47"), .Names = c("PDesc", 
            "Bsku"), class = "data.frame", row.names = 1L))), .Names = c("Group", 
        "Email", "Details"), class = "data.frame", row.names = 1L), 
        structure(list(Group = "ship", Email = "ga", Details = list(
            structure(list(PDesc = "D, C, S", Bsku = "47"), .Names = c("PDesc", 
            "Bsku"), class = "data.frame", row.names = 1L))), .Names = c("Group", 
        "Email", "Details"), class = "data.frame", row.names = 1L), 
        structure(list(Group = "ship", Email = "ga", Details = list(
            structure(list(PDesc = "D, T", Bsku = "47"), .Names = c("PDesc", 
            "Bsku"), class = "data.frame", row.names = 1L))), .Names = c("Group", 
        "Email", "Details"), class = "data.frame", row.names = 1L))), .Names = c("CTerms", 
"AUHistory", "VenDetails", "Purchaseitem"), row.names = c(NA, 
3L), class = "data.frame")

0 个答案:

没有答案