R 将不同长度向量的列表转换为“tible”`
我目前有一个不同长度的字符向量列表。像这样:R 将不同长度向量的列表转换为“tible”`,r,list,purrr,tibble,R,List,Purrr,Tibble,我目前有一个不同长度的字符向量列表。像这样: list( c('this','is','first'), c('this','is','second','it','longer'), c('this is a list','that is length 2') ) data_frame(column_1 = c('this is first', 'this is second it longer',
list(
c('this','is','first'),
c('this','is','second','it','longer'),
c('this is a list','that is length 2')
)
data_frame(column_1 =
c('this is first',
'this is second it longer',
'this is a list that is length 2'))
我想将列表中每个向量的所有元素合并到tibble
中的一行中。像这样:
list(
c('this','is','first'),
c('this','is','second','it','longer'),
c('this is a list','that is length 2')
)
data_frame(column_1 =
c('this is first',
'this is second it longer',
'this is a list that is length 2'))
如果可能的话,我想使用base R或来自
tidyverse
的包 您可以使用purrr
和stringr
x <- list(
c('this','is','first'),
c('this','is','second','it','longer'),
c('this is a list','that is length 2')
)
tibble(column1= map_chr(x, str_flatten, " "))
您可以使用
purr
和stringr
x <- list(
c('this','is','first'),
c('this','is','second','it','longer'),
c('this is a list','that is length 2')
)
tibble(column1= map_chr(x, str_flatten, " "))