[R] how to pass defined function with more than one arguments to apply?

About this list Date view Thread view Subject view Author view Attachment view

From: anoly (anoly16b@hotmail.com)
Date: Sat 29 May 2004 - 02:05:36 EST


Message-id: <SEA2-DAV23yPCTsc7Ke000248d3@hotmail.com>

Dear all:
I meet a problem of apply function. I have a matrix called tb
>tb
   V1 V2 V3
1 0 3 1
2 1 4 0
3 0 3 0
4 0 4 0
5 0 3 1
6 1 4 1
7 1 1 0
8 1 3 0
9 0 1 1
10 0 3 1

I hope to get the number of row that match c(0,3,1)
I do this way:
>length(apply(t(tb) = = c (0,3,1), 2, all))
 I defined a funtion, compare<-function(vector1, vector2){...}. For example,
compare(1:3, 1:3) will return TRUE. compare(1:3,2:4) return FALSE.
Then I hope to call apply(tb,1,compare). But this can not work, because
apply only pass one argument to compare function. Does anyone know how to
solve this problem?

Thanks so much.
Anoly

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Mon 31 May 2004 - 23:05:13 EST