Base R
tmp <- lapply(strsplit(quux[["Column A"]], ","), unique)
tmp <- lapply(tmp, `length<-`, max(lengths(tmp)))
tmp <- do.call(rbind, tmp)
colnames(tmp) <- paste0("col", 1:ncol(tmp))
cbind(quux, tmp)
# ID Column A col1 col2
# 1 1 A A <NA>
# 2 2 B,C B C
# 3 3 D,D,E D E
# 4 4 A,D A D
Another tidyverse option:
library(dplyr)
library(tidyr)
separate_longer_delim(quux, `Column A`, delim = ",") |>
distinct() |>
mutate(row = row_number(), .by = ID) |>
pivot_wider(id_cols = ID, names_from = row, values_from = `Column A`)
# # A tibble: 4 × 3
# ID `1` `2`
# <int> <chr> <chr>
# 1 1 A NA
# 2 2 B C
# 3 3 D E
# 4 4 A D
数据
quux <- structure(list(ID = 1:4, "Column A" = c("A", "B,C", "D,D,E", "A,D")), class = "data.frame", row.names = c(NA, -4L))