[R] R-How to unlist data frame multiple structured list column value and new column

muthu m muthu.psg.swift at gmail.com
Tue Nov 21 16:13:33 CET 2017


Hi,

How to unlist  list column value and add column into data frame.

Data frame

ID      ContractDe                                                                       PassengersDe                                                    TrainnerDe

  1      list(ConID=c("Zx","78yu"),ConRes = c("98","Tut"))                             list(PassID =1,PassIt="Lits,uy")                         list(Trnid=1,Trncont =5,EmpAddInfo=list(list(CohID ="pi",InVoice=77)))

  2      list(ConID=c("Half","Yut","Weq"),ConRes =c("ref","Cr"))                       list(PassID =c("pfil","Q"),Name ="Tic",PassIt="S5,Y1     list(Trnid=7,Trncont =3,EmpAddInfo=list(list(CohID =c("AB","NI","OL"),InVoice = c("4","Y"))))

  3      list(ConID=c("Ui","pric"),ConRes = c("Num","Patch"))                          list(PassID =1,PassIt ="St,Bp")                          list(Trnid=c("U", "l"),Trncont=c("10","78"),EmpAddInfo=list(list(CohID =c("AB","NI","OL"),InVoice =c("4","Y"))))

  4      list(ConID=c("2","7","IO"),ConRes = c("Res","Qty"),ConVal =c("Wno", "ip"))    list(PassID =1,Name ="RT",Name1 ="RR",PassIt="st7,st9")  list(Trnid=c("1", "3"),Trncont=c("yt","re"),EmpAddInfo=list(list(CohID =c("Ly","qp"),InVoice =c("2","P"))))





Expected data frame.

ID   ConID         ConRes    ConVal     PassID       PassIt    Name   Name1     Trnid    Trncont    CohID    InVoice

 1   Zx,78yu       98,Tut     NA          1          Lits,uy    NA     NA         1        5         pi         77

 2   Half,Yut,Weq  ref,Cr     NA          pfil,Q     S5,Y1      Tic    NA         7        3       AB,NI,OL     4,Y

 3   Ui,pric       Num,Patch  NA           1         St,Bp      NA     NA         U,l    10,78     AB,NI,OL     4,Y

 4   2,7,IO        Res,Qty    Wno,ip       1         st7,st9    RT     st7,st9     1,3   yt,re       Ly,qp      2,P



dput


structure(list(ID = c("1", "2", "3","4"), ContractDe = list(
    structure(list(ConID = c("Zx", "78yu"), ConRes = c("98",
    "Tut")), .Names = c("ConID", "ConRes"), class = "data.frame", row.names = 1:2),
    structure(list(ConID = c("Half", "Yut","Weq"), ConRes = c("ref",
    "Cr")), .Names = c("ConID", "ConRes"), class = "data.frame", row.names = 1:2),
structure(list(ConID = c("Ui", "pric"), ConRes = c("Num",
    "Patch")), .Names = c("ConID", "ConRes"), class = "data.frame", row.names = 1:2),
    structure(list(ConID = c("2", "7","IO"), ConRes = c("Res",
    "Qty"),ConVal=c("Wno","ip")), .Names = c("ConID", "ConRes","ConVal"), class = "data.frame", row.names = 1:2)),
    PassengersDe = list(structure(list(PassID = 1, PassIt = "Lits, uy"), .Names = c("PassID",
    "PassIt"), class = "data.frame", row.names = 1L), structure(list(
        PassID = c("pfil","Q"), Name = "Tic", PassIt = "S5, Y1"), .Names = c("PassID",
    "Name", "PassIt"), class = "data.frame", row.names = 1L),
structure(list(PassID = 1, PassIt = "St, Bp"), .Names = c("PassID",
    "PassIt"), class = "data.frame", row.names = 1L),
structure(list(PassID = 1, Name = "RT", Name1 = "RR", PassIt = "st7, st9"), .Names = c("PassID",
    "Name", "Name1", "PassIt"), class = "data.frame", row.names = 1L)),
    TrainnerDe = list(structure(list(Trnid = 1, Trncont = 5, EmpAddInfo = list(
        structure(list(CohID = "pi", InVoice = 77), .Names = c("CohID",
        "InVoice"), class = "data.frame", row.names = 1L))), .Names = c("Trnid",
    "Trncont", "EmpAddInfo"), class = "data.frame", row.names = 1L),
        structure(list(Trnid =7,Trncont = 3, EmpAddInfo = list(structure(list(
            CohID = c("AB", "NI", "OL"), InVoice = c("4", "Y")), .Names = c("CohID",
        "InVoice"), class = "data.frame", row.names = 1L))), .Names = c("Trnid",
        "Trncont", "EmpAddInfo"), class = "data.frame", row.names = 1L),
structure(list(Trnid =c("U","l"),Trncont =c("10","78"), EmpAddInfo = list(structure(list(
            CohID = c("AB", "NI", "OL"), InVoice = c("4", "Y")), .Names = c("CohID",
        "InVoice"), class = "data.frame", row.names = 1L))), .Names = c("Trnid",
        "Trncont", "EmpAddInfo"), class = "data.frame", row.names = 1L),
        structure(list(Trnid = c("1","3"), Trncont = c("yt","re"), EmpAddInfo = list(structure(list(
            CohID = c("Ly","qp"), InVoice = c("2","P")), .Names = c("CohID", "InVoice"
        ), class = "data.frame", row.names = 1L))), .Names = c("Trnid",
        "Trncont", "EmpAddInfo"), class = "data.frame", row.names = 1L))), .Names = c("ID",
"ContractDe", "PassengersDe", "TrainnerDe"), row.names = c(NA, 4L), class = "data.frame")


i was stuck on this change part of my project, please help me to out this. Thanks.



Sent from Outlook<http://aka.ms/weboutlook>

	[[alternative HTML version deleted]]



More information about the R-help mailing list