Counting values in data frame subject to conditions

Posted by unixsnob on Stack Overflow See other posts from Stack Overflow or by unixsnob
Published on 2012-07-06T15:12:52Z Indexed on 2012/07/06 15:15 UTC
Read the original article Hit count: 123

Filed under:

I have been searching around and I cannot figure out how to sumarise the data I have in my data frame (subject to some ranges). I know that it can be done when applying some combination of daaply/taaply or table but I haven't been able to get the exact result I was expecting.

Basically I want to turn this:

part_no val1 val2 val3 2 1 2 3 45.3

2 1 3 4 -12.3

3 1 3 4 99.3

3 1 5 2 -3.2

3 1 4 3 -55.3

Into this:

part_no val3_between0_50 val3_bw50_100 val3_bw-50_0 val3_bw-100_-50

2 1 0 0 1 0

3 0 1 0 1 1

This is dummy data, I got a lot more rows, but the idea is the same. I just want to count the number of values for a participant that meet certain condition.

If anyone could explain it sort of step by step, I would really appreciate it. I saw lots of different little posts around, but none do exactly this and my attempts only got me half way there. Like using table, etc.

Thanks!

© Stack Overflow or respective owner

Related posts about r