#' 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)))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.