R/norm1.R

Defines functions norm1

Documented in norm1

#' Normalize a vector to length 1
#' 
#' Scales a vector to a unit vector.
#' 
#' @param x a numeric vector
#' @author Matthias Templ
#' @keywords manip
#' @export
#' @examples
#' 
#' data(expenditures)
#' i <- 1
#' D <- 6
#' vec <- c(rep(-1/i, i), 1, rep(0, (D-i-1)))
#' 
#' norm1(vec)
#' 
norm1 <- function(x) {
  stopifnot(is.numeric(x) | is.integer(x))
  x / sqrt(sum(x^2))
}

Try the robCompositions package in your browser

Any scripts or data that you put into this service are public.

robCompositions documentation built on Aug. 25, 2023, 5:13 p.m.