I have this dataset:
data <- data.frame(column = c("apple, banana, cherry",
"apple, banana, cherry, grape",
"apple, banana, cherry, grape, pear"))
data
column
1 apple, banana, cherry
2 apple, banana, cherry, grape
3 apple, banana, cherry, grape, pear
I'd like my output to be:
column1 column2 column3 column4 column5
1 apple banana cherry NA NA
2 apple banana cherry grape NA
3 apple banana cherry grape pear
I tried: strsplit(data$column, ",")
, but this returns a list and I struggle to get it back into a dataframe type because the rows are of unequal length and this won't work: as.data.frame(strsplit(data$column, ","))
.
Thanks a lot!