Array generalization of
Arrays to be binded together
Value to pad array with; note default keeps integer status of arrays
Boolean, with default
Binds any number of arrays together, corner-to-corner. Because the
function is associative provided
pad is of length 1, this page
discusses the two array case.
x <- adiag(a,b) and
dim(b)=c(b_1,...,b_d). Then we have
Dimnames are preserved, if both arrays have non-null dimnames, and
pad is usually a length-one vector, but any vector is
acceptable; standard recycling is used. Be aware that the output array
dim(a)+dim(b)) is filled with (copies of)
b are copied. This can be
Returns an array of dimensions
dim(a)+dim(b) as described above.
a is a length-one vector, it is coerced
to an array of dimensions
b. If both
b are length-one vectors, return
b are arrays, function
length(dim(a))==length(dim(b)) (the function does not guess which
dimensions have been dropped; see examples section). In particular,
note that vectors are not coerced except if of length one.
adiag() is used when padding magic hypercubes in the context
of evaluating subarray sums.
Peter Wolf with some additions by Robin Hankin
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
a <- array( 1,c(2,2)) b <- array(-1,c(2,2)) adiag(a,b) ## dropped dimensions can count: b2 <- b1 <- b dim(a) <- c(2,1,2) dim(b1) <- c(2,2,1) dim(b2) <- c(1,2,2) dim(adiag(a,b1)) dim(adiag(a,b2)) ## dimnames are preserved if not null: a <- matrix(1,2,2,dimnames=list(col=c("red","blue"),size=c("big","small"))) b <- 8 dim(b) <- c(1,1) dimnames(b) <- list(col=c("green"),size=c("tiny")) adiag(a,b) #dimnames preserved adiag(a,8) #dimnames lost because second argument has none. ## non scalar values for pad can be confusing: q <- matrix(0,3,3) adiag(q,q,pad=1:4) ## following example should make the pattern clear: adiag(q,q,pad=1:36) # Now, a use for arrays with dimensions of zero extent: z <- array(dim=c(0,3)) colnames(z) <- c("foo","bar","baz") adiag(a,z) # Observe how this has # added no (ie zero) rows to "a" but # three extra columns filled with the pad value adiag(a,t(z)) adiag(z,t(z)) # just the pad value
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.