[R] how to combine apply and which or alternative ways to, do so

Gerrit Draisma gdraisma at xs4all.nl
Sun Aug 25 17:23:46 CEST 2013


Ha Guillaume,
Is this what you are looking for?

#---------------
x1<-sample(1:10,5,replace=FALSE)
x2<-sample(1:10,100,replace=TRUE)
#This
tapply(x1,1:5,FUN=function(i){which(x2==i)})
#or this
tapply(x1,x1,FUN=function(i){which(x2==i)})
#---------------

Gerrit



More information about the R-help mailing list