[R] unary operations
Barry Rowlingson
B.Rowlingson at lancaster.ac.uk
Tue Dec 23 10:39:02 CET 2003
Fredrik Lundgren wrote:
> 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?
Misunderstand what 'apply' does perhaps?
It applies your function to columns (the '2') of the matrix, and so
the function should only expect one argument, for example:
> apply(mat, 2, function(e1){print(e1)})
[1] 5 17
[1] 7 28
[1] 6 36
[1] 7 41
[1] 8 46
[1] 10 140
- in this toy example,my function is called with e1 set to columns of
the matrix.
So what were you trying to do with apply(mat, 2, function(e1,e2) e1*e2)?
Baz
More information about the R-help
mailing list