R/transform-divide-thousand.R

Defines functions transformDivideThousand

Documented in transformDivideThousand

#' Function to perform transformation
#'
#' This function applies a transformation, dividing variables by
#' 1000. If the vector is passed it applies the transformation to all variables
#' in the dataframe.
#' Source: http://stackoverflow.com/a/36912017/4417072
#'
#' @param dataframe = dataframe
#' @param optional = vectorListOfVariables
#' @export



transformDivideThousand <- function(data_frame, listofvars){
    if (missing(listofvars)) {
        data_frame[, sapply(data_frame, is.numeric)] =
            data_frame[, sapply(data_frame, is.numeric)]/1000
    } else {
        for (i in names(data_frame)) {
            if (i %in% listofvars) {
                data_frame[,i] = data_frame[,i]/1000
            }
        }
    }
    return(data_frame)
}
lf-araujo/sempsychiatry documentation built on May 21, 2019, 5:12 a.m.