Im am trying to split a column of a dataframe into 2 columns using transform
and colsplit
from reshape package. I don't get what I am doing wrong. Here's an example...
library(reshape)
df1 <- data.frame(col1=c("x-1","y-2","z-3"))
Now I am trying to split the col1
into col1.a
and col1.b
at the delimiter '-'. the following is my code...
df1 <- transform(df1,col1 = colsplit(col1,split='-',names = c('a','b')))
Now in my RStudio when I do View(df1)
I do get to see col1.a and col1.b split the way I want to.
But when I run...
df1$col1.a
or head(df1$col1.a)
I get NULL. Apparently I am not able to make any further operations on these split columns. What exactly is wrong with this?