Skip to contents

Creates an nrow-by-ncol identity matrix.

Usage

eye(nrow = 1, ncol = nrow)

Arguments

nrow

The desired number of rows.

ncol

The desired number of columns.

Value

A nrow-by-ncol identity matrix.

See also

Examples

eye(4) # 4-by-4 identity matrix
#>      [,1] [,2] [,3] [,4]
#> [1,]    1    0    0    0
#> [2,]    0    1    0    0
#> [3,]    0    0    1    0
#> [4,]    0    0    0    1
eye(4, 4) # 4-by-4 identity matrix
#>      [,1] [,2] [,3] [,4]
#> [1,]    1    0    0    0
#> [2,]    0    1    0    0
#> [3,]    0    0    1    0
#> [4,]    0    0    0    1
eye(3, 5) # 3-by-5 identity matrix
#>      [,1] [,2] [,3] [,4] [,5]
#> [1,]    1    0    0    0    0
#> [2,]    0    1    0    0    0
#> [3,]    0    0    1    0    0
eye(5, 3) # 5-by-3 identity matrix
#>      [,1] [,2] [,3]
#> [1,]    1    0    0
#> [2,]    0    1    0
#> [3,]    0    0    1
#> [4,]    0    0    0
#> [5,]    0    0    0