[R] Extending data frame with longer columns

Ralf B ralf.bierig at gmail.com
Wed Feb 17 10:00:01 CET 2010


Hi,

I am a beginner in R and have only read a few chapters in the R book,
I was not able to find a solution for this simple problem.

I have an empty data frame:

a=data.frame(name="test")

which I would like to extend in a for-loop (with data extracted from a
database). Ideally I would like to extend the data frame like this:

a["new_1"] = 1:10
a["new_1"] = 1:12
a["new_1"] = 1:14

R now obviously complains about the changing length of the new
columns. However, I would like to have missing values being added
whenever columns are shorter than a newer (longer) column. How can I
do that?

Thanks,
Ralf



More information about the R-help mailing list