[R] Appending elements to an array

Spencer Graves spencer.graves at pdf.com
Mon Jun 9 23:07:22 CEST 2003


Have you considered "rbind" to add?  Also, myArray[-2,] will remove row 
2 from myArray.

hope this helps.  spencer graves

Jonck van der Kogel wrote:
> Hi all,
> I am having a bit of trouble with the array structure of R. What I want 
> to do is dynamically add/remove elements to an array. For example:
> Let's say I have created an array:
>  > myArray <- array(c(3,8), dim=c(1,2))
>  > myArray
>      [,1] [,2]
> [1,]    3    8
> 
> And I now want to, for example, push an element (5,6) on to this array 
> so it will read:
>      [,1] [,2]
> [1,]    3    8
> [2,]    5    6
> 
> And then pop the first element of the array so the array now reads:
>      [,1] [,2]
> [1,]    5    6
> 
> How would I do this? So far I've only read how to create an array if you 
> know the dimensions beforehand, but I've been unable to find how to 
> dynamically add/remove elements to/from an array.
> 
> I've figured out how to do this with lists and vectors, but not with 
> arrays. For this particular structure I need to work with arrays.
> 
> Any help on how to do something like this would be much appreciated.
> Thanks, Jonck
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help




More information about the R-help mailing list