[R] a merge() problem

Sam Steingold sds at gnu.org
Sun Oct 7 23:44:16 CEST 2012


> * Peter Ehlers <ruyref at hpnytnel.pn> [2012-10-07 10:03:42 -0700]:
>
> On 2012-10-07 08:34, Sam Steingold wrote:
>> 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".
>
> The 'suffixes' argument refers to _non-by_ names only (as per ?merge).

yes, but "a" in "y" is _not_ a by-name.

-- 
Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000
http://www.childpsy.net/ http://americancensorship.org
http://think-israel.org http://www.memritv.org http://mideasttruth.com
Save time: send elected officials to jail directly, bypassing the office.




More information about the R-help mailing list