stm_keep_rows()
keeps the specified rows from a data frame or
matrix based on the provided indices.
Usage
stm_keep_rows(dat, indices, as_matrix = TRUE)
Arguments
- dat
A data frame or matrix from which rows are to be kept.
- indices
A vector of row indices to retain.
- as_matrix
A logical value indicating whether the result should
be converted to a matrix. Default is TRUE
.
Value
A data frame or matrix with the specified rows retained.
Details
This function uses stm_transform_keep_delete()
to retain the rows
specified in indices
. The result can optionally be returned as a
matrix based on the as_matrix
argument.
Examples
A <- matrix(1:15, ncol = 3, byrow = TRUE)
print(A)
#> [,1] [,2] [,3]
#> [1,] 1 2 3
#> [2,] 4 5 6
#> [3,] 7 8 9
#> [4,] 10 11 12
#> [5,] 13 14 15
stm_keep_rows(A, c(1, 3))
#> [,1] [,2] [,3]
#> [1,] 1 2 3
#> [2,] 7 8 9