AW: [R] unary operations

"Unternährer Thomas, uth" uth at zhwin.ch
Tue Dec 23 10:53:54 CET 2003



Hi, 

This should do what you are looking for:

x <- matrix(1:10, byrow = TRUE, nrow = 2)
mapply(function(x1, x2) x1+x2, x[1, ], x[2, ])	

But have also a look at colSums and colMeans


HTH

Thomas


-----Ursprüngliche Nachricht-----
Von: Fredrik Lundgren [mailto:fredrik.lundgren at norrkoping.mail.telia.com] 
Gesendet: Dienstag, 23. Dezember 2003 10:00
An: R-help
Betreff: [R] unary operations


Hello,

I had expected that the following should work

mat <- matrix(c(5, 7, 6, 7, 8, 10, 17, 28, 36, 41, 46, 140), nrow = 2, byrow = T) mat

apply(mat, 2, function(e1,e2) e1*e2)
apply(mat, 2, function(e1,e2) e1+e2)
apply(mat, 2, function(e1,e2) e1-e2)
apply(mat, 2, function(e1,e2) e1/e2)

but I get 

Error in FUN(newX[, i], ...) : Argument "e2" is missing, with no default

What do I do wrong?

Sincerely Fredrik Lundgren

______________________________________________
R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help




More information about the R-help mailing list