> I would like to know if there is a way to create a list or an array (or
> anything) which grows automatically as more elements are put into it. What I
> want to find is something equivalent to an ArrayList object of Java
> language. In Java, I can do the following thing:
>
> // Java code
> ArrayList myArray = new ArrayList();
> myArray.add("object1");
> myArray.add("object2");
> ....
> // End of java codeAs others have mentioned, you can do this with lists in R. However, there is an important difference between ArrayLists in Java and Lists in R. In Java, when an ArrayList grows past its bound, it doesn't allocate just enough space, it allocates a lot more, so the next time you allocate past the end of the array, there's space already reserved. This gives (IIRC) amortised O(n) behaviour. R doesn't do this however, so has to copy the entire array every time giving O(n^2) behaviour. Hadley ______________________________________________ [email protected] 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.
