Skip to content
Prev 305581 / 398506 Next

Count based on 2 conditions [Beginner Question]

Hello,

Since logical values F/T are coded as integers 0/1, you can use this:


set.seed(5712)  # make it reproducible
n <- 1e3
x <- data.frame(A = sample(0:1, n, TRUE), B = sample(0:10, n, TRUE))

count <- sum(x$A == 1 & x$B > 5)  # 207

Hope this helps,

Rui Barradas

Em 16-09-2012 11:41, SirRon escreveu: