Skip to contents

stm_delete_rows() deletes the specified rows from a data frame or matrix based on the provided indices.

Usage

stm_delete_rows(dat, indices, as_matrix = TRUE)

Arguments

dat

A data frame or matrix from which rows are to be deleted.

indices

A vector of row indices to delete.

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 deleted.

Details

This function uses stm_transform_keep_delete() to remove 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_delete_rows(A, 2)
#>      [,1] [,2] [,3]
#> [1,]    1    2    3
#> [2,]    7    8    9
#> [3,]   10   11   12
#> [4,]   13   14   15
stm_delete_rows(A, c(1, 3))
#>      [,1] [,2] [,3]
#> [1,]    4    5    6
#> [2,]   10   11   12
#> [3,]   13   14   15