Search code examples
rlistdata.tabledata-conversion

R convert list of characters and vectors into data.table of characters


I've got a list like the following:

    X              Y

   'A'           'B'
    c('G','F')     c('E','D') 

I need to convert it into a data.table like:

 X              Y

'A'           'B'
'G'           'E'
'F'           'D' 

Solution

  • An option would be to do unnest

    library(tidyverse)
    df1 %>%
        unnest(X, Y)
    

    In base R, we can do

    data.frame(lapply(df1, unlist))