[R] rbind-ing with empty data frame produces error

Jon Clayden jon.clayden at gmail.com
Thu Jan 25 16:22:14 CET 2007


Hi all,

I'm having some trouble with rbind - this may be a bug or it may be my
misunderstanding. If I do

fileName <- paste(tempdir(),"test.txt",sep="/")
file.create(fileName)
x <- read.table(fileName, col.names=c("one","two","three"))

I get a data frame with no rows, as documented. If I then try to rbind
this with another data frame with the same column names, I get an
error:

y <- data.frame(one=1,two=2,three=3)
rbind(x,y)

"Error in `*tmp*`[[jj]] : subscript out of bounds"

On the other hand, doing "rbind(as.matrix(x),as.matrix(y))" works as
expected. If this is, in fact, intended behaviour, could anyone
suggest another way of achieving what I want, please? I'm trying to
append to a data frame stored in a text file every so often, and of
course I need to create it, as above, the first time around...

My system is R-2.4.1/i686-pc-linux-gnu. Thanks in advance for your advice.

Regards,
Jon



More information about the R-help mailing list