#' Normalization on numerical features
#'
#' Rescale features to fall within 0 and 1.
#'
#' @param feature Vector of float numbers to normalize.
#' @param featureRange Vector of two float numbers indicating range of original feature.
#' @param newFieldName Character string used to form name for the normalized feature.
#'
#' @return Vector of rescaled values that fall between 0 and 1.
#'
#' @export
#'
#' @examples
#' normTerm_UsedPlat <- norm_01(feature = Data_UsedPlat$TermInMonths, featureRange = c(36, 72),
#' newFieldName = 'Term')
norm_01 <- function(feature, featureRange, newFieldName) {
scaled <- as.data.frame( if_else( feature > featureRange[2] | feature < featureRange[1],
0,
(feature - featureRange[1]) / (featureRange[2] - featureRange[1])
) )
names(scaled) <- paste0("norm", newFieldName)
return(scaled)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.