How can I turn a list of tibbles (all one col only) into a list of vectors?
The names of the list objects should stay the same and the col_name of the tibble should be omitted. Thanks for your help dear noble coders!
Example
a_tibble <- tibble(id = c('AB', 'DRR', 'FH', 'yyb'))
another_tibble <- tibble(id = c('AB', 'DXF', 'FH', 'DKH'))
list <- list(
list1 = a_tibble,
list2 = another_tibble,
list3 = a_tibble,
list4 = another_tibble)
expected result
result <- list(
list1 = (c('AB', 'DRR', 'FH', 'yyb')),
list2 = (c('AB', 'DXF', 'FH', 'DKH')),
list3 = (c('AB', 'DRR', 'FH', 'yyb')),
list4 = (c('AB', 'DXF', 'FH', 'DKH'))
)
>Solution :
You may unlist each list –
lapply(list, unlist, use.names = FALSE)
#$list1
#[1] "AB" "DRR" "FH" "yyb"
#$list2
#[1] "AB" "DXF" "FH" "DKH"
#$list3
#[1] "AB" "DRR" "FH" "yyb"
#$list4
#[1] "AB" "DXF" "FH" "DKH"