[R] how to pass defined function with more than one arguments to apply?
anoly
anoly16b at hotmail.com
Fri May 28 18:05:36 CEST 2004
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
More information about the R-help
mailing list