In my data frame I have some semi-structured data in a column.
df
col1
a|b|c
a b1|b|c
a & b2|b|c 3
from this dataframe$col1
I want to extract only the first word before the "|".
I tried using this
df$col2 <- unlist(strsplit(as.character(df$a),"[|]"))[[1]][1]
but the result was having same value of "a" on all the rows. Why is this and how to handle this ?
Thanks