Dario Federici
Dario Federici

Reputation: 1258

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' 

Upvotes: 0

Views: 470

Answers (1)

akrun
akrun

Reputation: 886938

An option would be to do unnest

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

In base R, we can do

data.frame(lapply(df1, unlist))

Upvotes: 3

Related Questions