使用合并功能遇到基本问题 [英] Having a basic issue using merge function

查看:134
本文介绍了使用合并功能遇到基本问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了merge()问题

I'm having a problem with merge()

我有两个数据框,一个是从SPSS(ssfia)导入的,另一个是我自己创建的.后者包含一个索引前者中两个变量重叠程度的变量.

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)

我想通过SPSS数据集(ssfia)的"ID"合并这个新的"match"变量,所以我制作了一个具有ID和新的Match变量的数据框.

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")

它给了我以下错误:

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!

推荐答案

如注释中所述,该列可能在matchf中不存在.试试:

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

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

然后重新运行合并.

这篇关于使用合并功能遇到基本问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆