i have two data frames which are cleaned and merged as a single csv file , the data frames are like this
**Source Master**
chang
If you want to check the Master.Names only against the first word in Names, this could do the trick:
Names$Mast <- NA
for(i in seq_len(nrow(Names)))
Names$Mast[i] <- grep(toupper(x = strsplit(Names[i,1]," ")[[1]][1]), Master.Names$V1,value=TRUE)
Edit
Using sapply instead of a loop could gain you some speed:
Names$Mast <- sapply(Names$V1, function(x) {
grep(toupper(x = strsplit(x," ")[[1]][1]), Master.Names$V1,value=TRUE)
})
Results
> Names
V1 Mast
1 chang chun petrochemical CHANG CHUN GROUP
2 chang chun plastics CHANG CHUN GROUP
3 church dwight CHURCH AND DWIGHT CO INC
4 citrix systems pacific CITRIX SYSTEMS ASIA PACIFIC P L
Data
Master.Names <- read.csv(text="CHANG CHUN GROUP
CHURCH AND DWIGHT CO INC
CITRIX SYSTEMS ASIA PACIFIC P L
CNH INDUSTRIAL N.V", header=FALSE)
Names <- read.csv(text="chang chun petrochemical
chang chun plastics
church dwight
citrix systems pacific", header=FALSE)