• rray_full_like() creates an array with the same type and size as x, but filled with value.

• rray_ones_like() is rray_full_like() with value = 1.

• rray_zeros_like() is rray_full_like() with value = 0.

rray_full_like(x, value)

rray_ones_like(x)

rray_zeros_like(x)

Arguments

x A vector, matrix, array or rray. A value coercible to the same inner type as x that will be used to fill the result (If x is an integer matrix, then value will be coerced to an integer).

Value

An object with the same type as x, but filled with value.

Details

No dimension names will be on the result.

Examples


x <- rray(1:10, c(5, 2))

# Same shape and type as x, but filled with 1
rray_full_like(x, 1L)#> <rray<int>[,2][5]>
#>      [,1] [,2]
#> [1,]    1    1
#> [2,]    1    1
#> [3,]    1    1
#> [4,]    1    1
#> [5,]    1    1
# fill is coerced to x if it can be
rray_full_like(x, FALSE)#> <rray<int>[,2][5]>
#>      [,1] [,2]
#> [1,]    0    0
#> [2,]    0    0
#> [3,]    0    0
#> [4,]    0    0
#> [5,]    0    0
# value = 1
rray_ones_like(x)#> <rray<int>[,2][5]>
#>      [,1] [,2]
#> [1,]    1    1
#> [2,]    1    1
#> [3,]    1    1
#> [4,]    1    1
#> [5,]    1    1
# When logicals are used, it is filled with TRUE
rray_ones_like(c(FALSE, TRUE))#> [1] TRUE TRUE
# value = 0
rray_zeros_like(x)#> <rray<int>[,2][5]>
#>      [,1] [,2]
#> [1,]    0    0
#> [2,]    0    0
#> [3,]    0    0
#> [4,]    0    0
#> [5,]    0    0