Index: src/library/base/R/merge.R =================================================================== --- src/library/base/R/merge.R (revision 74280) +++ src/library/base/R/merge.R (working copy) @@ -157,6 +157,14 @@ } if(has.common.nms) names(y) <- nm.y + ## If by.x %in% names(y) then duplicate column names still arise, + ## apply suffixes to just y - this keeps backwards compatibility + ## when referring to by.x in the resulting data.frame + dupe.keyx <- intersect(nm.by, names(y)) + if(length(dupe.keyx)) { + if(nzchar(suffixes[2L])) + names(y)[match(dupe.keyx, names(y), 0L)] <- paste(dupe.keyx, suffixes[2L], sep="") + } nm <- c(names(x), names(y)) if(any(d <- duplicated(nm))) if(sum(d) > 1L)