R/normalize.rsphere.R

#' Normalize values on a sphere
#'
#' @description Normalizes values of a vector such that the sum of squared elements equal to $r^2$.
#' @param x A vector or a matrix with values to be normalized.
#' @param r the diameter of a sphere, default 1.
#' @return It returns a data frame with normalized values.
#' @author Marjan Cugmas
#' @export

normalize.rsphere <- function (X,  r= 1) {
  if(is.vector(X)) r.sphere <- X * 1/sqrt(sum(X^2)) * r else r.sphere <- X * 1/sqrt(rowSums(X^2)) * r
  return(r.sphere)
}

Try the nem package in your browser

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

nem documentation built on April 23, 2021, 3 p.m.