[R] Q: appending to non-existent vector?
(Ted Harding)
Ted.Harding at manchester.ac.uk
Fri Sep 21 23:33:30 CEST 2007
On 21-Sep-07 17:15:08, D. R. Evans wrote:
> This is a real newbie question. What makes it worse is that I know
> I've seen the answer somewhere, but I can no longer find it.
>
> If I have a loop that is supposed to generate a vector piecemeal,
> adding an element each time through the loop, what do I do to stop it
> failing the first time around the loop, when the vector doesn't yet
> exist (so I can't use the append() function)?
I always use NULL, as in:
x<-NULL
for(...){ ... ; x<-c(x,...)}
It has not let me down yet!
Best wishes,
Ted.
--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 21-Sep-07 Time: 22:33:26
------------------------------ XFMail ------------------------------
More information about the R-help
mailing list