Create a matrix filled with the value x
.
Usage
fill(x, nrow = 1, ncol = 1, ..., atleast_2d = NULL)
falses(nrow = 1, ncol = 1, ..., atleast_2d = NULL)
trues(nrow = 1, ncol = 1, ..., atleast_2d = NULL)
ones(nrow = 1, ncol = 1, ..., atleast_2d = NULL)
zeros(nrow = 1, ncol = 1, ..., atleast_2d = NULL)
Arguments
- x
The (single) value to fill the matrix with.
- nrow
The desired number of rows.
- ncol
The desired number of columns.
- ...
Further dimensions of the array.
- atleast_2d
Logical indicating whether or not to force column vectors to have a second dimension equal to one. Defaults to
FALSE
. This behavior can also be changed globally using, for exampleoptions(atleast_2d = TRUE)
.
Examples
fill(pi, 3, 5) # 3-by-5 matrix filled with the value of pi
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 3.141593 3.141593 3.141593 3.141593 3.141593
#> [2,] 3.141593 3.141593 3.141593 3.141593 3.141593
#> [3,] 3.141593 3.141593 3.141593 3.141593 3.141593
fill(pi, 3, 5, 2, 2) # 3-by-5-by-2-by-2 array filled with the value of pi
#> , , 1, 1
#>
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 3.141593 3.141593 3.141593 3.141593 3.141593
#> [2,] 3.141593 3.141593 3.141593 3.141593 3.141593
#> [3,] 3.141593 3.141593 3.141593 3.141593 3.141593
#>
#> , , 2, 1
#>
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 3.141593 3.141593 3.141593 3.141593 3.141593
#> [2,] 3.141593 3.141593 3.141593 3.141593 3.141593
#> [3,] 3.141593 3.141593 3.141593 3.141593 3.141593
#>
#> , , 1, 2
#>
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 3.141593 3.141593 3.141593 3.141593 3.141593
#> [2,] 3.141593 3.141593 3.141593 3.141593 3.141593
#> [3,] 3.141593 3.141593 3.141593 3.141593 3.141593
#>
#> , , 2, 2
#>
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 3.141593 3.141593 3.141593 3.141593 3.141593
#> [2,] 3.141593 3.141593 3.141593 3.141593 3.141593
#> [3,] 3.141593 3.141593 3.141593 3.141593 3.141593
#>
pi * ones(3, 5)
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 3.141593 3.141593 3.141593 3.141593 3.141593
#> [2,] 3.141593 3.141593 3.141593 3.141593 3.141593
#> [3,] 3.141593 3.141593 3.141593 3.141593 3.141593
zeros(10)
#> [,1]
#> [1,] 0
#> [2,] 0
#> [3,] 0
#> [4,] 0
#> [5,] 0
#> [6,] 0
#> [7,] 0
#> [8,] 0
#> [9,] 0
#> [10,] 0
zeros(10, atleast_2d = TRUE)
#> [,1]
#> [1,] 0
#> [2,] 0
#> [3,] 0
#> [4,] 0
#> [5,] 0
#> [6,] 0
#> [7,] 0
#> [8,] 0
#> [9,] 0
#> [10,] 0