My data has the form:
groups <- c("4","4.2","4.2.1","4.2.1.1", "1", "1.2", "1.2.1", "1.2.1.2","1.2.1.2.1")
x <- data.frame(ID = c(rep("samp_1", 4), rep("samp_2", 5)), Group = groups)
How do I get this?:
ID col_1 col_2 col_3 col_4 col_5
samp_1 4 4.2 4.2.1 4.2.1.1 NA
samp_2 1 1.2 1.2.1 1.2.1.2 1.2.1.2.1
Each column will be determined by the length of the string, so all data in column 4 will have length 4 (or length 7 including the dots).
I am looking for the most general solution to this (e.g. using loops; using as few packages as possible) because I need to implement this in both R and Python.