[Rd] Bug in rbind.data.frame?

Duncan Murdoch murdoch@dunc@n @end|ng |rom gm@||@com
Sun Jan 30 12:50:19 CET 2022


I was surprised to see this result:

# This works:  Create a dataframe and add a row:
df <- data.frame(a = 1, b = 2)
rbind(df, c(3, 4))
#>   a b
#> 1 1 2
#> 2 3 4

# It doesn't work if the original dataframe is empty
df <- data.frame(a = numeric(), b = numeric())
rbind(df, c(1, 2))
#>   X1 X2
#> 1  1  2
# The column names changed!

# It doesn't matter if the new row is named:
rbind(df, c(a = 1, b = 2))
#>   X1 X2
#> 1  1  2

I tried this in a very old R version, and saw the same result, so it's 
not a new bug:  but is it maybe intentional, and if so, what is the 
reason for it?

Duncan Murdoch



More information about the R-devel mailing list