I'm using the tapply
function in order to get the count of variable over another variable. Here is the line of code: tapply(vip$VAR1,vip$VAR2,length)
However, I would like to filter only observations that have the value "1" on vip$VAR1
, can I do this with tapply
?
dat <- read.table(text = " VAR1 VAR2 admit num
0 0 0 7
0 0 1 1
0 1 0 3
0 1 1 7
1 0 0 5
1 0 1 1
1 1 0 0
1 1 1 6", header = TRUE)