I wrote this code and it worked, but I would like to improve it in order to solve it in a more efficient way, and avoid it to be too tedious.
library(magrittr)
library(dplyr)
B1 = A %>%
summarise( i0_5 = sum( (a > 0) & (b>= 0 & b< 5) & (d >=0 & d< 5) ),
i0_10 = sum( (a > 0) & (b>= 0 & b< 5) & (d >=0 & d< 10) ),
i0_15 = sum( (a > 0) & (b>= 0 & b< 5) & (d >=0 & d< 15) ),
i0_20 = sum( (a > 0) & (b>= 0 & b< 5) & (d >=0 & d< 20) ),
i0_25 = sum( (a > 0) & (b>= 0 & b< 5) & (d >=0 & d< 25) ),
i0_30 = sum( (a > 0) & (b>= 0 & b< 5) & (d >=0 & d< 30) ),
i0_35 = sum( (a > 0) & (b>= 0 & b< 5) & (d >=0 & d<= 35) ) )
B1=as.data.frame(t(B1))
B2 = A %>%
summarise( i0_5 = sum( (a > 0) & (b>= 0 & b< 10) & (d >=0 & d< 5) ),
i0_10 = sum( (a > 0) & (b>= 0 & b< 10) & (d >=0 & d< 10) ),
i0_15 = sum( (a > 0) & (b>= 0 & b< 10) & (d >=0 & d< 15) ),
i0_20 = sum( (a > 0) & (b>= 0 & b< 10) & (d >=0 & d< 20) ),
i0_25 = sum( (a > 0) & (b>= 0 & b< 10) & (d >=0 & d< 25) ),
i0_30 = sum( (a > 0) & (b>= 0 & b< 10) & (d >=0 & d< 30) ),
i0_35 = sum( (a > 0) & (b>= 0 & b< 10) & (d >=0 & d<= 35) ) )
B2=as.data.frame(t(B2))
B3 = A %>%
summarise( i0_5 = sum( (a > 0) & (b>= 0 & b< 15) & (d >=0 & d< 5) ),
i0_10 = sum( (a > 0) & (b>= 0 & b< 15) & (d >=0 & d< 10) ),
i0_15 = sum( (a > 0) & (b>= 0 & b< 15) & (d >=0 & d< 15) ),
i0_20 = sum( (a > 0) & (b>= 0 & b< 15) & (d >=0 & d< 20) ),
i0_25 = sum( (a > 0) & (b>= 0 & b< 15) & (d >=0 & d< 25) ),
i0_30 = sum( (a > 0) & (b>= 0 & b< 15) & (d >=0 & d< 30) ),
i0_35 = sum( (a > 0) & (b>= 0 & b< 15) & (d >=0 & d<= 35) ) )
B3=as.data.frame(t(B3))
B4 = A %>%
summarise( i0_5 = sum( (a > 0) & (b>= 0 & b< 20) & (d >=0 & d< 5) ),
i0_10 = sum( (a > 0) & (b>= 0 & b< 20) & (d >=0 & d< 10) ),
i0_15 = sum( (a > 0) & (b>= 0 & b< 20) & (d >=0 & d< 15) ),
i0_20 = sum( (a > 0) & (b>= 0 & b< 20) & (d >=0 & d< 20) ),
i0_25 = sum( (a > 0) & (b>= 0 & b< 20) & (d >=0 & d< 25) ),
i0_30 = sum( (a > 0) & (b>= 0 & b< 20) & (d >=0 & d< 30) ),
i0_35 = sum( (a > 0) & (b>= 0 & b< 20) & (d >=0 & d<= 35) ) )
B4=as.data.frame(t(B4))
B5 = A %>%
summarise( i0_5 = sum( (a > 0) & (b>= 0 & b< 25) & (d >=0 & d< 5) ),
i0_10 = sum( (a > 0) & (b>= 0 & b< 25) & (d >=0 & d< 10) ),
i0_15 = sum( (a > 0) & (b>= 0 & b< 25) & (d >=0 & d< 15) ),
i0_20 = sum( (a > 0) & (b>= 0 & b< 25) & (d >=0 & d< 20) ),
i0_25 = sum( (a > 0) & (b>= 0 & b< 25) & (d >=0 & d< 25) ),
i0_30 = sum( (a > 0) & (b>= 0 & b< 25) & (d >=0 & d< 30) ),
i0_35 = sum( (a > 0) & (b>= 0 & b< 25) & (d >=0 & d<= 35) ) )
B5=as.data.frame(t(B5))
B6 = A %>%
summarise( i0_5 = sum( (a > 0) & (b>= 0 & b< 30) & (d >=0 & d< 5) ),
i0_10 = sum( (a > 0) & (b>= 0 & b< 30) & (d >=0 & d< 10) ),
i0_15 = sum( (a > 0) & (b>= 0 & b< 30) & (d >=0 & d< 15) ),
i0_20 = sum( (a > 0) & (b>= 0 & b< 30) & (d >=0 & d< 20) ),
i0_25 = sum( (a > 0) & (b>= 0 & b< 30) & (d >=0 & d< 25) ),
i0_30 = sum( (a > 0) & (b>= 0 & b< 30) & (d >=0 & d< 30) ),
i0_35 = sum( (a > 0) & (b>= 0 & b< 30) & (d >=0 & d<= 35) ) )
B6=as.data.frame(t(B6))
B7 = A %>%
summarise( i0_5 = sum( (a > 0) & (b>= 0 & b< 35) & (d >=0 & d< 5) ),
i0_10 = sum( (a > 0) & (b>= 0 & b< 35) & (d >=0 & d< 10) ),
i0_15 = sum( (a > 0) & (b>= 0 & b<= 35) & (d >=0 & d< 15) ),
i0_20 = sum( (a > 0) & (b>= 0 & b<= 35) & (d >=0 & d< 20) ),
i0_25 = sum( (a > 0) & (b>= 0 & b<= 35) & (d >=0 & d< 25) ),
i0_30 = sum( (a > 0) & (b>= 0 & b<= 35) & (d >=0 & d< 30) ),
i0_35 = sum( (a > 0) & (b>= 0 & b<= 35) & (d >=0 & d<= 35) ) )
B7=as.data.frame(t(B7))
Em=cbind(B1,B2,B3,B4,B5,B6,B7)
colnames(Em) =c('0-5','0-10','0-15','0-20','0-25','0-30','0-35')
For the second table:
B1 = A %>%
summarise( i0_5 = sum( (a >= 0) & (b>= 0 & b< 5) & (d >=0 & d< 5) ),
i0_10 = sum( (a >= 0) & (b>= 0 & b< 5) & (d >=0 & d< 10) ),
i0_15 = sum( (a >= 0) & (b>= 0 & b< 5) & (d >=0 & d< 15) ),
i0_20 = sum( (a >= 0) & (b>= 0 & b< 5) & (d >=0 & d< 20) ),
i0_25 = sum( (a >= 0) & (b>= 0 & b< 5) & (d >=0 & d< 25) ),
i0_30 = sum( (a >= 0) & (b>= 0 & b< 5) & (d >=0 & d< 30) ),
i0_35 = sum( (a >= 0) & (b>= 0 & b< 5) & (d >=0 & d<= 35) ) )
B1=as.data.frame(t(B1))
B2 = A %>%
summarise( i0_5 = sum( (a >= 0) & (b>= 0 & b< 10) & (d >=0 & d< 5) ),
i0_10 = sum( (a >= 0) & (b>= 0 & b< 10) & (d >=0 & d< 10) ),
i0_15 = sum( (a >= 0) & (b>= 0 & b< 10) & (d >=0 & d< 15) ),
i0_20 = sum( (a >= 0) & (b>= 0 & b< 10) & (d >=0 & d< 20) ),
i0_25 = sum( (a >= 0) & (b>= 0 & b< 10) & (d >=0 & d< 25) ),
i0_30 = sum( (a >= 0) & (b>= 0 & b< 10) & (d >=0 & d< 30) ),
i0_35 = sum( (a >= 0) & (b>= 0 & b< 10) & (d >=0 & d<= 35) ) )
B2=as.data.frame(t(B2))
B3 = A %>%
summarise( i0_5 = sum( (a >= 0) & (b>= 0 & b< 15) & (d >=0 & d< 5) ),
i0_10 = sum( (a >= 0) & (b>= 0 & b< 15) & (d >=0 & d< 10) ),
i0_15 = sum( (a >= 0) & (b>= 0 & b< 15) & (d >=0 & d< 15) ),
i0_20 = sum( (a >= 0) & (b>= 0 & b< 15) & (d >=0 & d< 20) ),
i0_25 = sum( (a >= 0) & (b>= 0 & b< 15) & (d >=0 & d< 25) ),
i0_30 = sum( (a >= 0) & (b>= 0 & b< 15) & (d >=0 & d< 30) ),
i0_35 = sum( (a >= 0) & (b>= 0 & b< 15) & (d >=0 & d<= 35) ) )
B3=as.data.frame(t(B3))
B4 = A %>%
summarise( i0_5 = sum( (a >= 0) & (b>= 0 & b< 20) & (d >=0 & d< 5) ),
i0_10 = sum( (a >= 0) & (b>= 0 & b< 20) & (d >=0 & d< 10) ),
i0_15 = sum( (a >= 0) & (b>= 0 & b< 20) & (d >=0 & d< 15) ),
i0_20 = sum( (a >= 0) & (b>= 0 & b< 20) & (d >=0 & d< 20) ),
i0_25 = sum( (a >= 0) & (b>= 0 & b< 20) & (d >=0 & d< 25) ),
i0_30 = sum( (a >= 0) & (b>= 0 & b< 20) & (d >=0 & d< 30) ),
i0_35 = sum( (a >= 0) & (b>= 0 & b< 20) & (d >=0 & d<= 35) ) )
B4=as.data.frame(t(B4))
B5 = A %>%
summarise( i0_5 = sum( (a >= 0) & (b>= 0 & b< 25) & (d >=0 & d< 5) ),
i0_10 = sum( (a >= 0) & (b>= 0 & b< 25) & (d >=0 & d< 10) ),
i0_15 = sum( (a >= 0) & (b>= 0 & b< 25) & (d >=0 & d< 15) ),
i0_20 = sum( (a >= 0) & (b>= 0 & b< 25) & (d >=0 & d< 20) ),
i0_25 = sum( (a >= 0) & (b>= 0 & b< 25) & (d >=0 & d< 25) ),
i0_30 = sum( (a >= 0) & (b>= 0 & b< 25) & (d >=0 & d< 30) ),
i0_35 = sum( (a >= 0) & (b>= 0 & b< 25) & (d >=0 & d<= 35) ) )
B5=as.data.frame(t(B5))
B6 = A %>%
summarise( i0_5 = sum( (a >= 0) & (b>= 0 & b< 30) & (d >=0 & d< 5) ),
i0_10 = sum( (a >= 0) & (b>= 0 & b< 30) & (d >=0 & d< 10) ),
i0_15 = sum( (a >= 0) & (b>= 0 & b< 30) & (d >=0 & d< 15) ),
i0_20 = sum( (a >= 0) & (b>= 0 & b< 30) & (d >=0 & d< 20) ),
i0_25 = sum( (a >= 0) & (b>= 0 & b< 30) & (d >=0 & d< 25) ),
i0_30 = sum( (a >= 0) & (b>= 0 & b< 30) & (d >=0 & d< 30) ),
i0_35 = sum( (a >= 0) & (b>= 0 & b< 30) & (d >=0 & d<= 35) ) )
B6=as.data.frame(t(B6))
B7 = A %>%
summarise( i0_5 = sum( (a >= 0) & (b>= 0 & b<= 35) & (d >=0 & d< 5) ),
i0_10 = sum( (a >= 0) & (b>= 0 & b<= 35) & (d >=0 & d< 10) ),
i0_15 = sum( (a >= 0) & (b>= 0 & b<= 35) & (d >=0 & d< 15) ),
i0_20 = sum( (a >= 0) & (b>= 0 & b<= 35) & (d >=0 & d< 20) ),
i0_25 = sum( (a >= 0) & (b>= 0 & b<= 35) & (d >=0 & d< 25) ),
i0_30 = sum( (a >= 0) & (b>= 0 & b<= 35) & (d >=0 & d< 30) ),
i0_35 = sum( (a >= 0) & (b>= 0 & b<= 35) & (d >=0 & d<= 35) ) )
B7=as.data.frame(t(B7))
Em2=cbind(B1,B2,B3,B4,B5,B6,B7)
colnames(Em2) =c('0-5','0-10','0-15','0-20','0-25','0-30','0-35')