vec_len: Calculate Vector Length

View source: R/fracridge.R

vec_lenR Documentation

Calculate Vector Length

Description

Computes the Euclidean (L2) norm of a vector or the norm across a specified axis of a matrix.

Usage

vec_len(vec, axis = 1)

Arguments

vec

A numeric vector or matrix.

axis

An integer specifying the axis to compute the norm across. 1 for columns and 2 for rows. Default is 1.

Value

A numeric vector containing the Euclidean norms.

Examples

vec <- c(3, 4)
vec_len(vec)  # Should return 5

mat <- matrix(1:6, nrow = 2, ncol = 3)
vec_len(mat, axis = 1)  # Norms of rows
vec_len(mat, axis = 2)  # Norms of columns


bbuchsbaum/fmrireg documentation built on March 1, 2025, 11:20 a.m.