I have a variable called month that is a list of values separated by a | character (ex. "1 | 2 | 3"). The number of values in each cell is not the same, so some have "1 | 2" and others have "1 | 2 | 3 | 4". I need to separate month into month1, month2, etc. all the way to the maximum number of values separated by | in the column so that each value has its own column. Some rows should have NA for the columns that exceed their number of values in the original month column. I have no idea where to begin, but I've provided the a minimal reproducible example of what the variable/dataframe look like below.
id <- c("Lars", "Susan", "Juan")
month <- c("1 | 2", "1 | 2 | 3", "1 | 2 | 3 | 4")
df <- data.frame(id,month)