vendredi 1 avril 2016

Countif with multiple criterias in R

I would like to count all rows where two criterias are matched. My approach was:

a <- c(2,1,2,2,3,4,2,1,9)
b <- c(2,1,2,1,4,4,5,6,7)
c <- data.frame(a,b)
sum((c['a']==2) && (c['b']==2))

but for some reason this gives 1 instead of two. How could I count rows if multiple criterias are matched?

Aucun commentaire:

Enregistrer un commentaire