Skip to content
Prev 316881 / 398503 Next

cumulative sum by group and under some criteria

Hi,
res3<-with(res2,aggregate(cbind(cterm1_P1L,cterm1_P0H),by=list(m1,n1),max))

?res3[res3[,3]<0.6 & res3[,4]<0.95,] #this doesn't change the result as the conditions are ?not met
# ?Group.1 Group.2 cterm1_P1L cterm1_P0H
#1 ? ? ? 2 ? ? ? 2 ? ?0.01440 0.00273750
#2 ? ? ? 3 ? ? ? 2 ? ?0.00032 0.00250000
#3 ? ? ? 2 ? ? ? 3 ? ?0.01952 0.00048125

res3[res3[,3]<0.01 & res3[,4]<0.01,]
?# Group.1 Group.2 cterm1_P1L cterm1_P0H
#2 ? ? ? 3 ? ? ? 2 ? ?0.00032 ? ? 0.0025
Hope it helps.
A.K.