[R] apply() and unary operators

Robin Hankin r.hankin at auckland.ac.nz
Thu Mar 13 04:29:07 CET 2003


Hi everyone.

What's going on here?


> a <- matrix(1:4,2,2)
> a
     [,1] [,2]
[1,]    1    3
[2,]    2    4
> apply(a,2,sum)
[1] 3 7
> apply(a,2,"+")
     [,1] [,2]
[1,]    1    3
[2,]    2    4
> apply(a,1,"+")
     [,1] [,2]
[1,]    1    2
[2,]    3    4
> 

help(apply) says that "+" should be quoted but is otherwise silent on
unary operators.  I don't understand apply() here at all.

anyone?

-- 

Robin Hankin, Lecturer,
School of Geography and Environmental Science
Tamaki Campus
Private Bag 92019 Auckland
New Zealand

r.hankin at auckland.ac.nz
tel 0064-9-373-7599 x6820; FAX 0064-9-373-7042



More information about the R-help mailing list