[R] nameless functions in R

Rajarshi Guha rxg218 at psu.edu
Wed Dec 3 19:17:42 CET 2003


Hi,
  I have an apply statement that looks like:

> check.cols <- function(v1, v2) {
+     return( identical(v1,v2) );
+ }
> x
     [,1] [,2] [,3]
[1,]    1    3    3
[2,]    4    5    4
[3,]    2    7    6
> apply(x, c(2), check.cols, v2=c(7,8,9))
[1] FALSE FALSE FALSE

Is it possible to make the function check.cols() inline to the apply
statement. Some thing like this:

apply(x, c(2), funtion(v1,v2){ identical(v1,v2) }, v2=c(1,4,2))

The above gives me a syntax error. I also tried:

apply(x, c(2), fun <- funtion(v1,v2){ return(identical(v1,v2)) },
v2=c(1,4,2))

and I still get a syntax error.

Is this type of syntax allowed in R?

Thanks,

-------------------------------------------------------------------
Rajarshi Guha <rxg218 at psu.edu> <http://jijo.cjb.net>
GPG Fingerprint: 0CCA 8EE2 2EEB 25E2 AB04 06F7 1BB9 E634 9B87 56EE
-------------------------------------------------------------------
He who is in love with himself has at least this advantage -- he won't
encounter many rivals.
-- Georg Lichtenberg, "Aphorisms"




More information about the R-help mailing list