problem with conditional column sums

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

problem with conditional column sums

curtburk
This post has NOT been accepted by the mailing list yet.
Hey everyone,

I'm having a problem figuring out how to get the sum of each column conditional upon the value in the column. I've pasted a subset of my data below and basically for each column I want to know how many "I"s are in each column. I used the following line of code:
apply(status,2,function(x) {sum(x==I,na.rm = TRUE)})

The output tells me that there are 0 "I"s in each column, but it's clear that is not true. Any help would be greatly appreciated.

Thanks

   
   2010 2011 2012
1     A    A    A
2     A    I     I
3     A    A    A
4     U    U    U
5     A    A    A
6     I     I    I
7     U    I    I
8     A    U   A
9     I    A    U
10    I    I    I
Reply | Threaded
Open this post in threaded view
|

Re: problem with conditional column sums

JS Huang
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: problem with conditional column sums

gnustats
CONTENTS DELETED
The author has deleted this message.