From sundar.dorai-raj at pdf.com  Thu Sep 25 18:47:11 2003
From: sundar.dorai-raj at pdf.com (sundar.dorai-raj@pdf.com)
Date: Thu Sep 25 17:46:29 2003
Subject: [Rd] merge.data.frame problem (PR#4299)
Message-ID: <200309251547.h8PFlB0P029780@pubhealth.ku.dk>

Full_Name: Sundar Dorai-Raj
Version: 1.7.1
OS: Windows 2000
Submission from: (NULL) (4.18.65.62)


Hi all,
  I just discovered a problem when merging two data.frames which don't have any
columns in common and when one (or both) of the data.frames is a single column.
E.g.

x <- data.frame(x = 1:5, y = letters[1:5])
y <- data.frame(z = 1:2)
z <- merge(x, y)

The result z is as expected, but the resulting names of z are not right. I've
tracked it down to following the line in merge.data.frame:

if (l.b == 0) {
  ij <- expand.grid(1:nx, 1:ny)
  res <- cbind(x[ij[, 1], ], y[ij[, 2], ]) # <---
}

Changing this line to:

res <- cbind(x[ij[, 1], , drop = FALSE], y[ij[, 2], , drop = FALSE])

resolves the problem.


[Rd] merge.data.frame problem (PR#4299)
sundar.dorai-raj@pdf.com