[Rd] merge.data.frame problem (PR#4299)

sundar.dorai-raj at pdf.com sundar.dorai-raj at pdf.com
Thu Sep 25 18:47:11 MEST 2003


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.



More information about the R-devel mailing list