I have a column in my dataframe with words like this.
ColA
2-4 Model
Group1
Group ACH
Group2
Phenols
Group1
Group ACH
Group2
MONO MHPP
Group1
Group ACH
Group2
I want to create two additional columns like this: 1) without keywords c("Group1", "Group (ACH)", "Group2") and 2) a second column that retains only those bag of words.
ColA ColB ColC
2-4 Model 2-4 Model
Group1 Group1
Group (ACH) Group (ACH)
Group2 Group2
Phenols Phenols
Group1 Group1
Group (ACH) Group (ACH)
Group2 Group2
MONO MHPP MONO MHPP
Group1 Group1
Group (ACH) Group (ACH)
Group2 Group2
I tried gsub and str_replace but no results. So any suggestion is much appreciated.
You may use an
ifelse-If in general, you want to check for all
"Group"values you may usegreplinstead of mentioning all of them inval.