Skip to content
Prev 345847 / 398502 Next

Equivalent to matlab ".*" operator in R

Not sure you really want the overhead of sweep() for this, but logically, you want z as a vector or maybe 1d array since sweep() is designed as complimentary to apply(). I.e., you can sweep out marginal means using, say,

m <- matrix(c(5, 7, 9, 13), 2)
colmean <- apply(m, 2, mean)
sweep(m, 2, colmean, "-")

in which colmean is a vector. In general, apply() yields an array with fewer extents, and sweep expects one.

-pd
On 19 Nov 2014, at 16:00 , D?nes T?th <toth.denes at ttk.mta.hu> wrote: