On 14/10/07 5:39 PM, Louis Martin wrote: > I am looking for an efficient and fast way for doing this: > > for (v in 1:dw) {ok <-list1[v,] > > for (z in 1:5) {kk = ok[z] ; > for (o in 1:t) {if (kk== list[o]) n<- n+1}} > show(n) } > > list1 : a data.frame with nrow = dw ; ncol = z; > list2 : a data.frame with nrow = 1 ; ncol = t > with t > z
Is the following close to what you want? cumsum(apply(list1[,1:5], 1, function(x) sum(x %in% list2))) Here list2 is a vector, not a data frame. Duplicates in list2 are not counted twice, unlike in your code, but you could run it again just on the duplicates (and again on the triplicates, etc) if this is needed. Hope this helps, James -- James Reilly Department of Statistics, University of Auckland Private Bag 92019, Auckland, New Zealand ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.