I have two data frames which I need to merge based on candidate and constituency column. Now the problem here is that in both of the data frames there are discrepancies between the spelling of names in both the data frames.
For example in one data frame name is Dr. Ashutosh Singh in other it is Dr Ashutosh Singh. In one data frame name is Dr. Vikash Singh in another its Vikash Singh.
I'm attaching a screenshot of both the data frames. first data frame
I have to map first data frame columns CAND_NAME and AC_NAME to the second data frame columns candidate and constituency respectively and have to merge them in one.
I'm sharing the Excel file too and the R code. I have to merge the three sheets into one.
Link for the excel file
R Code
setwd("/home/lenovo/Documents/r_prog/")
library(readxl)
candidate2017=read_excel("LA 2017.xlsx", sheet = 1)
electors2017=read_excel("LA 2017.xlsx", sheet = 2)
ManipurCandidates2017ADR=read_excel("LA 2017.xlsx", sheet = 3)
ManipurCandidate2017=candidate2017[grepl("Manipur", candidate2017$ST_NAME),]
ManipurElectors2017=electors2017[grepl("Manipur", electors2017$ST_NAME),]
ManipurElectors2017 = data.frame(lapply(ManipurElectors2017, function(v) {
if (is.character(v)) return(toupper(v))
else return(v)
}))
ManipurCandidates2017ADR = data.frame(lapply(ManipurCandidates2017ADR, function(v) {
if (is.character(v)) return(toupper(v))
else return(v)
}))
ManipurCandidate2017 = data.frame(lapply(ManipurCandidate2017, function(v) {
if (is.character(v)) return(toupper(v))
else return(v)
}))
View(ManipurCandidate2017)
View(ManipurElectors2017)
View(ManipurCandidates2017ADR)
mergedData = merge(ManipurCandidate2017,ManipurCandidates2017ADR ,
by.x=c('CAND_NAME'), by.y=c('Candidate'), all = TRUE)
I am new to R please help. Thanks In advance.