which.in: [+] Get indices of certain matrix elements

Description Usage Arguments Value Author(s) See Also Examples

View source: R/which.in.R

Description

Get indices of certain (e.g., diagonal) matrix elements. These elements can be in:

  1. diag - diagonal;

  2. offdiag - offdiagonal;

  3. col - indicated columns;

  4. row - indicated rows;

  5. trilow - lower triangle (with or without diagonal);

  6. triupp - upper triangle (with or without diagonal).

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13

Arguments

type

Either diag, offdiag, col, row, trilow or triupp (just for which.in()).

x

A matrix or an object, which can be coerced to a marix.

...

Other appropriate parameters indicated below.

col

An index/Indices of columns that contain elements of interest.

row

An index/Indices of rows that contain elements of interest.

diag

logical. Should the diagonal be included?

Value

Indices of indicated elements of a matrix.

Author(s)

Vilmantas Gegzna

See Also

Other matrix operations in spMisc: corr_vec2mat(), indMatrix(), nTri2nDiag(), revalueMatrix(), sort_matrix_elements, which.max.all(), which.max.perRow()

Examples

 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
m1 <- matrix(NA, 5, 5)
m1

 #>        [,1] [,2] [,3] [,4] [,5]
 #>  [1,]   NA   NA   NA   NA   NA
 #>  [2,]   NA   NA   NA   NA   NA
 #>  [3,]   NA   NA   NA   NA   NA
 #>  [4,]   NA   NA   NA   NA   NA
 #>  [5,]   NA   NA   NA   NA   NA

which.in.diag(m1)
 #>  [1]  1  7 13 19 25

m2 <- matrix(NA, 2, 5)
which.in.diag(m2)
 #>  [1]  1  4

#================================

 which.in(diag,    m1)
 which.in(offdiag, m1)

 which.in(col, m1, col = 2)
 which.in(row, m1, row = 2)

 which.in(trilow, m1)
 which.in(trilow, m1, diag = TRUE)

 which.in(triupp, m1)

GegznaV/spMisc documentation built on April 26, 2020, 5:59 p.m.