A generalized procedure for real life datasets might be out<-rep(matrix(arg),ncol(ma))-ma out[which(arg==0),]<--out[which(arg==0),] out Ozgur -- View this message in context: http://r.789695.n4.nabble.com/Ifelse-on-matrix-using-a-vector-argument-tp4632485p4632490.html Sent from the R help mailing list archive at Nabble.com.