Recently, I have started to learn R and trying to explore more by automating the process. Below is the sample data and I'm trying to create a new column by finding and replacing the particular text within the label (colname:Designations).
Since, I'm getting this work with loads of new data I would like to automate using R programming than using excel formulas.
Dataset:
strings<-c("Zonal Manager","Department Manager","Network Manager","Head of Sales","Account Manager","Alliance Manager","Additional Manager","Senior Vice President","General manager","Senior Analyst", "Solution Architect","AGM")
R code i used:
**t<-data.frame(strings,stringsAsFactors = FALSE)**
**colnames(t)[1]<-"Designations"**
**y<-sub(".*Manager*","Manager",strings,ignore.case = TRUE)**
Challenge: In this all the data got changed as Manager but I needed to replace other designations with the main themes.
I tried with ifelse statement, grep, grepl, str,sub, etc but I didn't get what I'm looking for
I can't use first/second/last words (as'delimit') since the main themes scatters to and fro.. Eg: Chief Information Officer or Commercial Finance Manager or AGM
Excel Work: I have already coded 300 main themes as...
Manager (for all GM, Asst.Manager,Sales Manager,etc) Architect (Solution Arch, Sr. Arch, etc) Director (Senior Director, Director, Asst.Director, etc) Senior Analyst Analyst Head (for head of sales)
What I'm looking for: I needed to create a new column and should replace the text with the relevant main themes as I did in excel using R.
I'm ok if i can take the main themes that I have already coded in excel to match the themes using R programming (as vlookup in excel).
Thanks in advance for your help!
Aucun commentaire:
Enregistrer un commentaire