[R] Extending a vector
pburns at pburns.seanet.com
Sat Apr 3 11:58:15 CEST 2004
There is a problem with this scheme that has nothing to do with
syntax. Extending objects dynamically like this is probably the
surest way to run out of memory. If you know the final length an
object will be, then it is best to create the object at its full length
and then subscript into it with assignments.
In this application you apparently don't know what the final length
will be. In this case you can create an object of some length,
subscript into it with assignments (keeping track of how much has
gone in), then grow the object again by some chunk when more
room is needed.
patrick at burns-stat.com
+44 (0)20 8525 0696
(home of S Poetry and "A Guide for the Unwilling S User")
Mark O. Kimball wrote:
>I believe this should be an easy thing to do...
>I have a function I repeatably call which takes input parameters and
>outputs columns to various data frames. I also wish to keep a summary of
>certain values as I call the function. I though keeping the values in a
>vector then appending the vector by the new amounts would be the way to
>Example: (this is what I want even thought the below syntax is wrong)
>a <- 1
>print(a) --> 1
>a <- c(a,2)
>print(a) --> 1,2
>a <- c(a,2,4,5)
>print(a) --> 1,2,2,4,5
>Any help would be greatly appreciated...
More information about the R-help