With df:
df <- data.frame(value=abs(rnorm(100, 25, 5)), status=sample(0:1,100,replace=T))
df$value[sample(1:100,5)] <- NA
I need to get a frequency (percentage) table (better return a matrix) like the following:
value | status(0) status(1)
----------------------------
<=25 | 23 (23%) 20 (20%)
>25 | 27 (27%) 25 (25%)
NA | 3 (3%) 2 (2%)
I can do this using:
br <- seq(0, 50, 25)
with(df, summary(cut(value[status==0], br, labels=br[-1],
include.lowest=T, ordered_result=T)))
with(df, summary(cut(value[status==1], br, labels=br[-1],
include.lowest=T, ordered_result=T)))
But would there be a one-time way to return a matrix as above? Thanks!