The rbind on empty and nonempty data frames behaves inconsistently. I am
not sure if by design.

In the first example, first row is deleted, which may or may not be on
purpose:
df1 <- data.frame()
df2 <- data.frame(foo=c(1, 2), bar=c("a", "b"))
rbind(df1, df2)
    foo  bar
2   2     b

Now if we continue:
df1 <- data.frame(matrix(0, 0, 2))
names(df1) <- names(df2)
    foo bar
2     1   a
3     2   b
So now data frames combined successfully, but the row names have been
increased by one.

Finally, if row names are strings, it works okay:
row.names(df2) <- c("row1", "row2")
rbind(df1, df2)
          foo bar
row1    1   a
row2    2   b

Is this behaviour by design?

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to