R-如何动态取消列出数据帧列表列和按列值分组

时间:2017-11-13 05:36:25

标签: r

我有一个名为df的数据框,如何取消列出dataframe列和按列值分组。

我的数据框。

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#,如果cust#值相同,我正在创建包含值的列表并计算该值。例如:cust#44 in 1 row and 2行是常见的,所以我将每个值分组     44 DID列表(值= c(“200”,“300”),计数= c(3,1))。这里的200的数量是3,300是2,通过将第1行和第3行分组为普通的cust# 44.etc。

帮助我实现这一目标。

我的预期数据框。

`cust#`   ColumnHeader      ColValues   

    44       CTerms          list(Value = c("Valid","Invalid"),Count=c(1,1))                              
    44       DID             list(Value = c("200","300"),Count=c(3,1))
    44       Dprice          list(Value = c("$652.94","$252.04","$652.94.04","$27.4"),Count=c(1,1,1,1))
    44       CADD            list(Value = c("SHi","US"),count=C(2,2))
    44       Group           list(Value = "ship", Count=2)
    44       Email           list(Value = "ga", Count=2)
    44       PDesc           list(Value = c("D","C","T"),Count=c(2,1,1))
    44       Bsku            list(Value = "47", Count=2)
    45       CTerms          list(Value = "Test", Count=1)
    45       DID             list(Value = c("400","20"), Count=c(1,1))
    45       Dprice          list(Value = "$252.04", Count=2)
    45       CADD            list(Value = c("SHi","US"), Count=c(1,1))
    45       Group           list(Value = "ship", Count=1)
    45       Email           list(Value = "ga", Count=1)
    45       PDesc           list(Value = c("D","C","S"),Count=c(1,1,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 个答案:

没有答案