[R] Adding zeros in each dimension of an array

David Winsemius dwinsemius at comcast.net
Wed Jun 7 18:03:30 CEST 2017


> On Jun 7, 2017, at 8:33 AM, li li <hannah.hlx at gmail.com> wrote:
> 
> For a data frame, we can add an additional row or column easily. For
> example, we can add an additional row of zero and an additional row of
> column as follows.
> 
> Is there an easy and similar way to add zeros in each dimension? For
> example, for
> array(1:12, dim=c(2,2,3))?
> 
> Thanks for your help!!
>   Hanna
> 
> 
> 
>> x <- as.data.frame(matrix(1:20,4,5))> x[5,] <- 0> x[,6] <- 0> x  V1 V2 V3 V4 V5 V6
> 1  1  5  9 13 17  0
> 2  2  6 10 14 18  0
> 3  3  7 11 15 19  0
> 4  4  8 12 16 20  0
> 5  0  0  0  0  0  0
> 

Try installing the abind package.


> 	[[alternative HTML version deleted]]

And learn to post in plaint text.


> 
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

David Winsemius
Alameda, CA, USA



More information about the R-help mailing list