I have a dataframe df as shown below
name position
1 HLA 1:1-15
2 HLA 1:2-16
3 HLA 1:3-17
I would like to split the position column into two more columns based on the ":" character such that i get
name seq position
1 HLA 1 1-15
2 HLA 1 2-16
3 HLA 1 3-17
So i thought this would do the trick,
df <- transform(df,pos = as.character(position))
df_split<- strsplit(df$pos, split=":")
#found this hack from an old mailing list post
df <- transform(df, seq_name= sapply(df_split, "[[", 1),pos2= sapply(df_split, "[[", 2))
however I get an error
Error in strsplit(df$pos, split = ":") : non-character argument
What could be wrong? How do you achieve this in R. I have simplified my case here, actuality the dataframe runs to over a hundred thousand rows.
dput
your data.frame? $\endgroup$