How to add new column from list column value

后端 未结 2 1652
暖寄归人
暖寄归人 2020-12-21 07:29

How to unlist list column and add new column from unlist column value in data frame.Can you please find my df below.

My data Frame.

Status       Audi         


        
2条回答
  •  盖世英雄少女心
    2020-12-21 07:56

    As each of the list columns has a different structure, you'll have to deal with them in different ways.

    With base R:

    dfnew <- data.frame(df$Status,
                        do.call(rbind, lapply(df$AuditResult, function(x) sapply(x, toString))),
                        do.call(rbind, df$Deship),
                        do.call(rbind, lapply(df$Item, unlist)))
    names(dfnew) <- sub('^.*\\.','',names(dfnew))
    

    which gives:

    > dfnew
        Status      DDID   Dvalue UserID        Add Menu Bill IDesc vendor
    1   Active  2, First Bpin, 67      1 Stet, Bpin    1    9     A      5
    2 Inactive Second, 8   CA, 98      2 Stet, Bpin    1    8 B,N,O      4
    3   OnHold 78, 8, NA   UK, 76      1 Stet, Bpin    1    7   L,q      2
    

提交回复
热议问题