Having a basic issue using merge function

2019-08-08 08:13发布

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!

标签: r merge match
1条回答
干净又极端
2楼-- · 2019-08-08 08:37

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.

查看更多
登录 后发表回答