R/replace_outliers_df.R

#' Apply replace.outliers to all columns of a data.frame grouped by days
#'
#' This is a wrapper function for replace_outliers. It applies replace_outliers over the columns of a data.frame, grouped by day. This function returns a data.frame of the same size as df, with the same values of df, except for those outliers as defined in replace_outliers.
#' @param df df is a data.frame with any number of numerical columns, and one id column named "day".
#' @keywords windsorization, outliers, grouped by day
#' @export
#' @examples
#' replace.outliers()

replace_outliers_df <- function(df){ #Takes a data.frame and returns a data.frame
  library(dplyr)
  df %>%   #Pass data frame
    group_by(day) %>%
    mutate_all(funs(replace.outliers)) %>% #apply function to all columns in grouped data.frame
    as.data.frame() #mutate_all returns a "tibble", so we convert it back to data.frame
}
jemilianosf/GrisLab documentation built on May 14, 2019, 2:44 p.m.