Hi,

I would like to make a conditional sum for certain columns in a dataframe.

This is how my dataframe looks like:

Clinic Rep ColM1 ColM2 ColM3 ... ColM40
A      1     1    0      0        1
B      1     0    -1     0        0
C      1     0    -1     1        -1 
A      2     1    1      -1       0
B      2     -1   0      0        1 
C      2     1    0      1       -1

I would like to have two new dataframes so that
Dataframe1: with the count of all 1

Clinic  ColM1  ColM2 ColM3 .. ColM40
A        2      1    0         1
B        0      0    0         1
C        1      0    2         0

Dataframe2: with the count of all -1

Clinic  ColM1  ColM2 ColM3 .. ColM40
A        0      0    1         0
B        1      1    0         0
C        0      1    0         2


Is there an easy way to achieve this.
Thx,
Bert

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to