R: Split character column and create two new ones
问题 R users I have a data frame similar to this: a <- c("John, 3 years") b <- c("Mokobe, 11 years") c <- c("Ivan") df <- rbind(a,b,c) df [,1] a "John, 3 years" b "Mokobe, 11 years" c "Ivan" Which function should I use to split the column after comma to get: df [,1] [,2] John 3 years Mokobe 11 years Ivan NA 回答1: we can do a strsplit by the delimiter , and then rbind the list elements after padding with NA at the end to make length same for each list element lst <- strsplit(df[,1], ", ") do.call