I am looking to create new columns in an R data frame based on characters stored in an existing column. For example, suppose I have the following data frame:
> df = data.frame(retroid = c("loftk001", "vizq001"), pitchcount = c("BBBCCFB", "CCX"))
> df
retroid pitchcount
1 loftk001 BBBCCFB
2 vizq001 CCX
I want to create new columns, "p1, p2, p3", etc. such that it looks like
retroid pitchcount p1 p2 p3 p4 p5 p6 p7
1 loftk001 BBBCCFB B B B C C F B
2 vizq001 CCX C C X
One of the potential problems I am facing is that the strings stored under column "pitchcount" are of variable length. As in the case above, if the string in "pitchcount" has less characters than the maximum, I just want empty values in the corresponding columns.
Is there a fast way to do this in R?
Thank you in advance!