I have a data frame like so:
before<- data.frame( Var1=
c("174_1","174_1","174_2","174_3","175_1","175_1"))
I would like to add another column Var2
that contains the part of the expression in Var1
before the underscore. The new column would appear as follows:
after<- data.frame( Var1=
c("174_1","174_1","174_2","174_3","175_1","175_1"), Var2=
c("174","174","174","174","175","175"))
I am believe functions like grepl() could be useful for this, however, I do not know how to specify keeping part of an before the grepl("_").