R/mag.R

Defines functions mag

Documented in mag

#' Magnitudes of vectors.
#'
#' Get the Euclidean norm of a single vector or each row of an nx3 matrix.
#'
#' @param x vector or \code{n x 3} matrix
#'
#' @return the norm of x, or an n-vector giving the norm of each row of x (for a matrix)
#'
#' @author John Brzustowski \email{jbrzusto@@REMOVE_THIS_PART_fastmail.fm}

mag = function(x) {
    if (length(x) <= 3)
        sqrt(sum(x^2))
    else
        apply(x, 1, function(x) sqrt(sum(x^2)))
}
jbrzusto/sensorgnome-R-package documentation built on May 18, 2019, 9:19 p.m.