我创建了2个数据框,我试图合并它。但它显示错误:“fix.by(by.x,x)中的错误:'by'必须指定唯一有效的列”

时间:2018-04-13 06:17:17

标签: r dataframe merge

student<-data.frame("Roll_No"=c("202","203","204","205","206","157"),"First_Name"=c("Shahrukh","Shakti","Shantanu","Shashank","Shirke","Abhinav"),"Last_Name"=c("Khan","Rawat","Verma","Sinha","Ganesh","MIshra"),"State"=c("MP","MP","UT","UP","Maharashtra","MP"))

elec<-data.frame("Roll"=c("202","203","204","205","206","157"),"Subjects"=c("Operations","Operations","Operations","Analytics","Marketing","Marketing"))
print(student)
print(elec)

kpv <- merge(student,elec,by.x = c("ROll_No"),by.y = c("ROll"))

1 个答案:

答案 0 :(得分:1)

注意变量名称的区分大小写。在这里,我在合并调用中调整了它们:

student<-data.frame("Roll_No"=c("202","203","204","205","206","157"),"First_Name"=c("Shahrukh","Shakti","Shantanu","Shashank","Shirke","Abhinav"),"Last_Name"=c("Khan","Rawat","Verma","Sinha","Ganesh","MIshra"),"State"=c("MP","MP","UT","UP","Maharashtra","MP"))

elec<-data.frame("Roll"=c("202","203","204","205","206","157"),"Subjects"=c("Operations","Operations","Operations","Analytics","Marketing","Marketing")) 

print(student)
print(elec)

kpv <- merge(student,elec,by.x = c("Roll_No"),by.y = c("Roll"))
kpv