mirror of
https://github.com/agdamsbo/REDCapCAST.git
synced 2024-11-27 15:21:55 +01:00
extension to forcats::fct_drop to perform across data.frame
This commit is contained in:
parent
daf0e7852f
commit
9cae725de2
29
R/fct_drop.R
Normal file
29
R/fct_drop.R
Normal file
@ -0,0 +1,29 @@
|
||||
#' Drop unused levels preserving label data
|
||||
#'
|
||||
#' This extends [forcats::fct_drop()] to natively work across a data.frame and
|
||||
#' replace [base::droplevels()].
|
||||
#'
|
||||
#' @param x Factor to drop unused levels
|
||||
#' @param ... Other arguments passed down to method.
|
||||
#' @export
|
||||
#'
|
||||
#' @importFrom forcats fct_drop
|
||||
#' @export
|
||||
#' @name fct_drop
|
||||
NULL
|
||||
|
||||
#' @rdname fct_drop
|
||||
#' @export
|
||||
fct_drop.data.frame <- function(x, ...) {
|
||||
purrr::map(\(.x){
|
||||
if (is.factor(.x)){
|
||||
forcats::fct_drop(.x)
|
||||
} else {
|
||||
.x
|
||||
}
|
||||
}) |>
|
||||
dplyr::bind_cols()
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user