pindex: Get Values in a Matrix by Pair-wise Indices

Description Usage Arguments Value Examples

View source: R/utils.R

Description

Get Values in a Matrix by Pair-wise Indices

Usage

1
pindex(m, i, j)

Arguments

m

A matrix or a 3-dimension array.

i

Row indices or the indices in the first dimension.

j

Column indicies or the indices in the second dimension.

Value

If m is a matrix, the value returned is a vector c(m[i1, j1], m[i2, j2], ...)'.

If m is an array, the value returned is a matrix rbind(m[i1, j1, ], m[i2, j2, ], ...)'.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
m = matrix(rnorm(100), 10)
m2 = m[m > 0]
ind = do.call("rbind", lapply(1:10, function(ci) {
    i = which(m[, ci] > 0)
    cbind(i = i, j = rep(ci, length(i)))
}))
pindex(m, ind[, 1], ind[, 2])
identical(pindex(m, ind[, 1], ind[, 2]), m[m > 0])

# 3d array
arr = array(1:27, dim = c(3, 3, 3))
pindex(arr, 1:2, 2:3)
identical(pindex(arr, 1:2, 2:3),
   rbind(arr[1, 2, ], arr[2, 3, ]))

ComplexHeatmap documentation built on Nov. 14, 2020, 2:01 a.m.