Skip to content
Prev 13277 / 398503 Next

fastest way to multiply each column of a matrix by a single vlaue

On Mon, 3 Sep 2001, Jason Liao wrote:

            
You don't need the rep because of the re-cycling rule.  Either

B <- matrix(b, m, n, byrow=T)

or, a litle faster

A/rep(b, rep(m, n))


You'll find the S/R system code uses the last most often.

[...]