title: Sum a column based on condition in another column in R
body: <p>I have a dataset with 150+ columns and 1000s of rows. The dataset provides a flag for different items for various categories in different columns. One of the columns is total usage for each item across the category. Below is sample of the dataset:</p>
  
  <pre><code>Values   A B C
  1        Y   
  2          Y
  3        Y   Y 
  4            Y 
  </code></pre>
  
  <p>I want to use R to do calculations such that I get the following results:</p>
  
  <pre><code>     Count  Sum
  A      2     4
  B      1     2
  C      2     7
  </code></pre>
  
  <p>Basically I want the Count Column to give me the number of "y" for A, B and C, and the Sum column to give me sum from the Usage column for each time there is a "Y" in Columns A, B and C</p>
  
  <p>Step 2 -  I have similar column values in 200 + files. I have brought all the files into a folder. What I would like to do is use the above functions, apply it in each of the file, and then have the answer grouped by file and category. for example</p>
  
  <p><code>File 1 Count A Sum A Count B Sum B Count C Sum C</code></p>
  
  <p><code>File 2 Count A Sum A Count B Sum B Count C Sum C</code></p>
  
  <p>and so on</p>