Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

sweep_cols.matrix

Suptract a elements of a vector from respective columns of a matrix


Description

An optimized function equivalent to sweep(x, 2, STATS) for a matrix x.

Usage

sweep_cols.matrix(x, STATS, disable_checks = FALSE)

Arguments

x

a numeric matrix;

STATS

a numeric vector whose length equals to the number of columns of x.

disable_checks

if TRUE, do not check that x is a numeric matrix and its number of columns matches the length of STATS; set in production code for a significant speed-up.

Value

A matrix of the same attributes as x.

Examples

x <- matrix(runif(1000), ncol=4)
s <- 1:4

stopifnot(all.equal(sweep_cols.matrix(x, s), sweep(x, 2, s)))

statnet.common

Common R Scripts and Utilities Used by the Statnet Project Software

v4.4.1
GPL-3 + file LICENSE
Authors
Pavel N. Krivitsky [aut, cre] (<https://orcid.org/0000-0002-9101-3362>), Skye Bender-deMoll [ctb]
Initial release
2020-10-03

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.