Having a basic issue using merge function

℡╲_俬逩灬. 提交于 2020-01-05 13:08:34

问题


I'm having a problem with merge()

I have two data frames, one that I imported from SPSS (ssfia) and one that I created on my own. The latter contains a variable indexing the degree of overlap between two variables in the former.

match<-ifelse(ssfia$Func_Source==ssfia$Symptom_Source,1,0)

I want to merge this new "match" variable by "ID" the SPSS dataset (ssfia), so I made a data frame with ID and my new Match variable.

matchf<-data.frame(match,ssfia$ID)

Now I try to merge them...

merge(ssfia,matchf,by="ID")

And it gives me the following error:

Error in fix.by(by.y, y) : 'by' must specify uniquely valid column(s)

I tried searching this site for similar problems, but everyone else seems to have a more nuanced issue. I'm guessing this will be something pretty simple. Any help would be greatly appreciated!


回答1:


As noted in the comments, that column probably doesn't exist in matchf. Try:

matchf <- data.frame(match, ID=ssfia$ID)

Then re-run the merge.



来源:https://stackoverflow.com/questions/21708282/having-a-basic-issue-using-merge-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!