Вот один вариант с read.csv
и split
df1 <- read.csv(text = v, header = FALSE, stringsAsFactors = FALSE)
lapply(split(df1[-1], df1[,1]), function(x) na.omit(unlist(x, use.names = FALSE)))
Или другой вариант с tidyverse
library(dplyr)
library(tibble)
library(tidyr)
enframe(v) %>%
separate_rows(value) %>%
group_by(name) %>%
mutate(name1 = value[1]) %>%
slice(-1) %>%
ungroup %>%
select(-name) %>%
unstack(value ~ name1)
#$a
#[1] "1" "2"
#$b
#[1] "4" "5" "6"
#$c
#[1] "x"
Или с str_remove
и str_replace
str_remove(v, '.,') %>%
strsplit(',') %>%
set_names(str_extract(v, '.'))
#$a
#[1] "1" "2"
#$b
#[1] "4" "5" "6"
#$c
#[1] "x"