search for: expandarray

Displaying 2 results from an estimated 2 matches for "expandarray".

2017 Jun 07
0
Adding zeros in each dimension of an array
...he eye of the beholder. a <- array( 1:12, dim = c( 2, 2, 3 ) ) b <- array( 0, dim = dim( a ) + 1 ) b[ 1:2, 1:2, 1:3 ] <- a If you want to do a lot of this, it could be wrapped for convenience though implementing that last expression without hardcoding the sequences may not be obvious: expandArray <- function( a ) { b <- array( 0, dim = dim( a ) + 1 ) do.call( `[<-`, c( list( b ), lapply( dim( a ), seq.int ), list( a ) ) ) } expandArray( a ) On Wed, 7 Jun 2017, li li wrote: > For a data frame, we can add an additional row or column easily. For > example, we can add an...
2017 Jun 07
3
Adding zeros in each dimension of an array
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