Thursday, 5 September 2013

Splitting a string into different columns

Splitting a string into different columns

What I am trying to accomplish is splitting a column into multiple
columns. I would prefer the first column to contain "F", second column
"US", third "CA6" or "DL", and the fourth to be "Z13" or "U13" etc etc. My
entire df follows the same pattern of X.XX.XXXX.XXX or X.XX.XXX.XXX or
X.XX.XX.XXX and I know the third column is where my problem lies because
of the different lengths. I have only used substr in the past and I could
use that here with some if statements but would like to learn how to use
stringr package and POSIX to do this (unless there is a better option).
Thank you in advance.
Here is my df:
c("F.US.CLE.V13", "F.US.CA6.U13", "F.US.CA6.U13", "F.US.CA6.U13",
"F.US.CA6.U13", "F.US.CA6.U13", "F.US.CA6.U13", "F.US.CA6.U13",
"F.US.DL.U13", "F.US.DL.U13", "F.US.DL.U13", "F.US.DL.Z13", "F.US.DL.Z13"
)

No comments:

Post a Comment