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

From: Jon Clayden <jon.clayden_at_gmail.com>
Date: Thu 25 Jan 2007 - 15:22:14 GMT


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



R-help@stat.math.ethz.ch 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. Received on Fri Jan 26 02:49:46 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 25 Jan 2007 - 17:30:30 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.