Skip to contents

stm_keep_cols() retains specified columns from a data frame. It uses stm_transform_keep_delete() to perform the operation.

Usage

stm_keep_cols(dat, indices, as_matrix = TRUE)

Arguments

dat

A data frame or matrix from which columns will be retained.

indices

A numeric vector or logical vector indicating the columns to retain.

as_matrix

Optional. A logical value indicating whether the result should be returned as a matrix. Default is TRUE.

Value

A data frame or matrix containing only the specified columns.

Details

This function uses stm_transform_keep_delete() to retain the specified columns in the given data. If as_matrix is TRUE, the result is returned as a matrix, otherwise a data frame is returned.

Examples

A <- matrix(1:15, ncol = 5, byrow = TRUE)
print(A)
#>      [,1] [,2] [,3] [,4] [,5]
#> [1,]    1    2    3    4    5
#> [2,]    6    7    8    9   10
#> [3,]   11   12   13   14   15
stm_keep_cols(A, 2)
#>      [,1]
#> [1,]    2
#> [2,]    7
#> [3,]   12
stm_keep_cols(A, 2, as_matrix = FALSE)
#> [1]  2  7 12