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

Wolski wolski at molgen.mpg.de
Fri May 28 18:15:55 CEST 2004


Hi!

?apply
...: optional arguments to 'FUN'.

you can pass more arguments to your function.
length(apply(tb,comare,c(0,3,1)))


Sincerely
Eryk.

*********** REPLY SEPARATOR  ***********

On 5/28/2004 at 12:05 PM anoly wrote:

>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 at 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



Dipl. bio-chem. Eryk Witold Wolski    @    MPI-Moleculare Genetic   
Ihnestrasse 63-73 14195 Berlin       'v'    
tel: 0049-30-83875219               /   \    
mail: wolski at molgen.mpg.de        ---W-W----    http://www.molgen.mpg.de/~wolski




More information about the R-help mailing list