#' Centimeter to other units converter
#'
#' This function allows you to convert centimeters to other distance units
#'
#' @param
#' number - number to convert
#' @param
#' to - add unit to convert to, available units 'km', 'm', 'ft', 'in', 'mile'
#'
#' @return Function returns converted values
#' @export
#' @examples
#' cm_to(100, 'm')
#'
#' height = c(170, 184, 192)
#' cm_to(height, 'ft')
#'
cm_to <- function(number, to) {
x = dplyr::case_when(to == "km" ~ "0.0001",
to == "m" ~ "0.01",
to == "ft" ~ "0.032808399",
to == "in" ~ "0.393700787",
to == "mile" ~ "6.21371192e-06",
TRUE ~ as.character(NA))
if (is.na(x)) warning("incorrect measure unit")
return(number * as.numeric(x))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.