I need to merge many data.frames. Below the sample of the code to reproduce an error. It looks like a bug.
This code works well:
df1 <- data.frame(v=1:10, v2=rev(1:10))
df2 <- data.frame(vv=1:8, v2=rev(5:12))
df12 <- merge(x=df1, y=df2, by.x=1, by.y=1, all=TRUE, suffixes=c(".x", ".y"))
df3 <- data.frame(w=2:6, v2=3:7)
df123 <- merge(x=df12, y=df3, by.x=1, by.y=1, all=TRUE, suffixes=c(".x", ".y"))
df4 <- data.frame(x=1:6, v2=1:6)
df1234 <- merge(x=df123, y=df4, by.x=1, by.y=1, all=TRUE, suffixes=c(".x", ".y"))
This code produce the error message on the last line: Error in match.names(clabs, names(xi)) : names do not match previous names. The only change is that nrow(df4) > nrow(df123)
df1 <- data.frame(v=1:10, v2=rev(1:10))
df2 <- data.frame(vv=1:8, v2=rev(5:12))
df12 <- merge(x=df1, y=df2, by.x=1, by.y=1, all=TRUE, suffixes=c(".x", ".y"))
df3 <- data.frame(w=2:6, v2=3:7)
df123 <- merge(x=df12, y=df3, by.x=1, by.y=1, all=TRUE, suffixes=c(".x", ".y"))
df4 <- data.frame(x=1:16, v2=1:16)
df1234 <- merge(x=df123, y=df4, by.x=1, by.y=1, all=TRUE, suffixes=c(".x", ".y"))
Let's see names of columns of df123
names(df123)
[1] "v" "v2.x" "v2.y" "v2"
Then change the last name on arbitrary one
names(df123)[4] <- "v3"
And now this line of code will work correctly
df1234 <- merge(x=df123, y=df4, by.x=1, by.y=1, all=TRUE, suffixes=c(".x", ".y"))
Is it bug? I used R 2.13.1 on Win7. If you need some other information, I'll add it to the question.