Skip to content
Prev 138155 / 398506 Next

elegant way to minus on each row of a matrix

try this:

mat <- matrix(1:9, 3, 3, TRUE)
dat <- as.data.frame(mat)
vec <- 1:3

result.mat <- mat - vec
result.dat <- dat - vec
result.mat
result.dat


I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
      http://www.student.kuleuven.be/~m0390867/dimitris.htm


Quoting Bo Zhou <bozhou1981 at hotmail.com>:
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm