indAndSub: Retrieve vector or array indices

Description Usage Arguments Details Examples

Description

ind2sub is a synonym for arrayInd in base package.

Usage

1
2
3
ind2sub(ind, .dim, .dimnames = NULL, useNames = FALSE)

sub2ind(sub, .dim)

Arguments

ind

Vector indices.

.dim

dim(.) integer vector

.dimnames

optional list of character dimnames(.). If useNames is true, to be used for constructing dimnames for arrayInd() (and hence, which(*, arr.ind=TRUE)). If names(.dimnames) is not empty, these are used as column names. .dimnames[[1]] is used as row names.

useNames

logical indicating if the value of arrayInd() should have (non-null) dimnames at all.

sub

Array/matrix indices.

Details

ind2sub is just an alias for arrayInd

Examples

1
2
3
4
5
6
set.seed(12345)
mat <- matrix(round(runif(6, min = 0, max = 10)), nrow = 2, ncol = 3)
ind2sub(4, dim(mat))
sub2ind(c(2, 2), dim(mat))
subs <- as.matrix(expand.grid(1:2,2:3))
sub2ind(subs, dim(mat))

chgigot/cgmisc documentation built on May 14, 2019, 8:17 a.m.