Skip to content
Prev 152100 / 398500 Next

convert for loop into apply()

If length( levels( a1$cat ) ) is not very large, and the 
structure suggested in the toy example holds in the actual case (probes in 
a2 do not 'overlap' and are in order according to a2$st and a2$en, then 
this might do:
+   tmp1 <- subset( a1, cat==x )
+   tmp2 <- subset( a2, cat==x)
+   findInterval( tmp1$en, tmp2$st )-findInterval( tmp1$st, tmp2$en+1 )
+ }), a1$cat)
[1] 1 1 2 2 0 1
HTH,

Chuck
On Sun, 3 Aug 2008, Bill.Venables at csiro.au wrote:

            
Charles C. Berry                            (858) 534-2098
                                             Dept of Family/Preventive Medicine
E mailto:cberry at tajo.ucsd.edu	            UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901