jeudi 15 février 2018

Find the number of row matching conditions on other rows

if I have a data frame A:

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

How could I obtain a data frame B which contains:

The number of times where z value is equal to 1 AND -> a values are among 5 and 10, (5 <= i <=10) AND b values are among 0 and 5.

The number of times where z value is equal to 1 AND -> a values are among 5 and 10, (5 <= i <=10) AND c values are among 0 and 5.

The number of times where z value is equal to 1 AND -> a values are among 5 and 10, (5 <= i <=10) AND d values are among 0 and 5.

The data frame B would contain 3 columns related to b,c and d where it says the number of rows that match the condition.. it would be for this case:

The only row where z value is 1 and a values are among 5-10 is the row4: 4 0 1 8 0 6 3

B:
b.     c.     d.
1      0      1

The values on column b and d are 1 because 0 and 3 are among 0 and 5, but c value is equal to 6, which doesn't satisfy the condition.

Aucun commentaire:

Enregistrer un commentaire