Gabor Grothendieck wrote: > For the problem at hand I think I would use your solution > which is both easily understood and fastest. On the > other hand the tapply based solutions are coordinate > free (i.e. no explicit mucking with indices) and readily > generalize to more than 2 groups -- just replace [^pq] with > [^pqr], say. > >
for sure, mine was optimized towards the case, not towards generalizability. the gsubfn one is a loser, though. but the first one *is* easily generalizable, e.g., letters = "pqrs" sapply(sprintf("^[^%s]*%s", letters, unlist(strsplit(letters, split=""))), grep, x=x, value=TRUE) while an order of magnitude faster than the tapply ones. vQ ______________________________________________ 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.