lundi 12 février 2018

How to find the number of rows which match a condition

If I have a dataframe A like

A:
x.     y.     z.     a.     b.     c. 
1      0      0      3      0      0
2      0      0      5      6      5
3      0      0      6      8      2
4      0      1      8      0      6
5      0      0      20     2      0
6      0      1      3      3      7

How could I obtain a data frame B like: 3 columns, each one related to a, b and c columns of data frame A.. containing the numbers of rows which match the following condition:

The number of times where a, b and c values are among 5 and 10, (5 <= i <=10) AND z value is equal to 1. For instance: in column a, the row 3 is 6 which is >5 and < 10, but z. value is not 1 then that row is not count. On the other hand in the row 4, a. is >5 and < 10, and z. value is 1, then this row is counted.

B would be like:

B:
a.      b.      c.
1       1       2

Aucun commentaire:

Enregistrer un commentaire