R 中的合并命令
我一直在使用 R 中的合并命令,并试图找出如何使用 SUFFIX 参数。在线文档并没有很好地解释它。
我想做的是导入一些 csv 文件:
data1<-read.csv("fileA", header=T)
data2<-read.csv("fileB", header=T)
然后使用合并命令来合并它们。但是,我希望某些变量能够真正合并,而其他具有相同名称的变量则由它们来自的文件进行标记。例如,如果我的两个电子表格中都存在“NAME”变量,那么我希望它们正常合并,但如果出现“GRADE”变量,它将更改为 GRADE.fileA 和 GRADE .文件B。我已经能够获得 GRADE.x 和 GRADE.y,但我更喜欢这些变量上有更有用的标签。对此的任何帮助将不胜感激。谢谢。
I have been playing around with the merge command in R and am trying to figure out how to use the SUFFIX parameter. The online documentation does not do a very good job at explaining it.
What I'd like to do is import some csv files:
data1<-read.csv("fileA", header=T)
data2<-read.csv("fileB", header=T)
And then use the merge command to merge them. However, I would like for some variables to be truly merged, while other variables that hold the same name to be labeled by the file they came from. So for instance, if a "NAME" variable existed in both of my spreadsheets, then I'd like for them to be merged as normal, but if a "GRADE" variable showed up, it would be changed to GRADE.fileA and GRADE.fileB. I am already able to get GRADE.x and GRADE.y, but I would prefer more useful labels on these variables. Any help on this would be appreciated. Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我猜测您没有在
merge
中明确指定by
arg。你想要这样的东西吗?I'm guessing that you didn't explicitly specify the
by
arg inmerge
. Do you want something like this?我认为这应该有效:
I think this should work: