#' Select scale scores
#'
#' Selects variables generated by [score_scale()] from a data frame.
#'
#' @param data A data frame
#' @param names_only If TRUE, variable names are returned instead of a data
#' frame
#' @param index_only If TRUE, variable indices are returned instead of a data
#' frame
#' @return A data frame, a vector with variable names, or a vector with indices.
#' @export
select_scores <- function(data,
names_only = FALSE,
index_only = FALSE) {
id <- which(
sapply(data, function(x) isTRUE(dic_attr(x, .opt$class) == "score"))
)
if (names_only) return(names(data)[id])
if (index_only) return(id)
data[, id, drop = FALSE]
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.