extract.array

0th

Percentile

Extract a subset of an array, matrix or a vector with unknown dimensions

Extract a subset of an array, matrix or a vector with unknown dimensions. This method is useful when you do not know the number of dimensions of the object your wish to extract values from, cf. example.

Usage
## S3 method for class 'array}(x, ..., drop=FALSE, indices=list(...))':
extractundefined

x{An array or a matrix.}
 ...{These arguments are by default put into the
    indices list.}
 indices{A list of index vectors to be extracted.
    The names (coerced to integers) of the list elements are the
    dimension indices for each of the index vectors.}
 drop{If TRUE, dimensions of length one are dropped,
    otherwise not.}

Returns an array.

cat("\nCreatean array 'x' with a random number of dimensions:
")
maxdim <- 4
dim <- sample(3:maxdim, size=sample(2:maxdim, size=1), replace=TRUE)
ndim <- length(dim)
dimnames <- list()
for (kk in 1:ndim)
  dimnames[[kk]] <- sprintf("%s%d", letters[kk], 1:dim[kk])
x <- 1:prod(dim)
x <- array(x, dim=dim, dimnames=dimnames)

cat("\nArray'x':
")
print(x)


cat("\nExtract'x[2:3,...]':
")
print(extract(x, "1"=2:3))

cat("\nExtract'x[3,2:3,...]':
")
print(extract(x, "1"=3,"2"=2:3))

cat("\nExtract'x[...,2:3]':
")
indices <- list(2:3)
names(indices) <- length(dim(x))
print(extract(x, indices=indices))

[object Object]

slice.index()


methods
programming
Aliases
  • extract.array
  • extract.array
  • extract.matrix
  • extract.default
Documentation reproduced from package R.utils, version 0.7.9, License: LGPL version 2.1 or newer (the releases)

Community examples

Looks like there are no examples yet.