[R] a merge() problem

arun smartpink111 at yahoo.com
Sun Oct 7 19:50:35 CEST 2012


Hi,

Though, this does give the result you wanted when the column names are the same.
 y1<-y
 colnames(y1)<-c("a","b")
merge(x,y1,by="a",all=TRUE,suffixes=c("",".y"))
#  a b  b.y
#1 1 4    a
#2 2 5    b
#3 3 6 <NA>
A.K.




----- Original Message -----
From: Sam Steingold <sds at gnu.org>
To: r-help at r-project.org
Cc: 
Sent: Sunday, October 7, 2012 11:34 AM
Subject: [R] a merge() problem

I know it does not look very good - using the same column names to mean
different things in different data frames, but here you go:
--8<---------------cut here---------------start------------->8---
> x <- data.frame(a=c(1,2,3),b=c(4,5,6))
> y <- data.frame(b=c(1,2),a=c("a","b"))
> merge(x,y,by.x="a",by.y="b",all.x=TRUE,suffixes=c("","y"))
  a b    a
1 1 4    a
2 2 5    b
3 3 6 <NA>
Warning message:
In merge.data.frame(x, y, by.x = "a", by.y = "b", all.x = TRUE) :
  column name 'a' is duplicated in the result
--8<---------------cut here---------------end--------------->8---
why is the suffixes argument ignored?
I mean, I expected that the second "a" to be "a.y".
(when I omit suffixes, the result is the same).
Thanks.
-- 
Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000
http://www.childpsy.net/ http://palestinefacts.org http://honestreporting.com
http://truepeace.org http://openvotingconsortium.org
My name is Deja Vu. Have we met before?

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.





More information about the R-help mailing list