title: Calculating percentages of "1s" in one column based on two other columns in R
body: <p>I am a R Newbie. Sorry for asking basic question. 
  I have "data" that consists of three columns (as an example) named data$engine, data$unit, and data$AvailableLeft. data$AvailableLeft is dummy (0 or 1). And for each unique value of data$engine, there can be several values of data$unit. I would like to calculate percent of "1s" in data$AvailableLeft for each value of data$engine and data$unit respectively. I have hundred thousands of rows but pasted the first 13 rows only. </p>
  
  <pre><code> data$engine  data$unit     data$AvailableLeft
      10158       207                1
      10158       207                0
      10158       207                1
      10158       207                0
      10147       142                1
      10147       142                1
      10147       142                1
      10147       142                0
      10147       142                1
      10147       142                0
      10147       142                1
      10161       244                0
      10161       244                0
  </code></pre>
  
  <p>I would like to have my output in this format:</p>
  
  <pre><code>    data$engine  data$unit            Percentage
       10158          207                  20%
       10147          142                  10%
       10161          244                  3%
         .             .                    .
         .             .                    .
         .             .                    .
  </code></pre>
  
  <p>I tried these codes but was not successful:</p>
  
  <pre><code> ##calculate the percentage of "1s" for whole data and not for each data$engine and data$unit
  sum(data$AvailableLeft==1)/length(data$AvailableLeft) 
  
  # tried to do it in parts but was not able to divide the two columns at last...
  df11 &lt;- data.frame(data$engine, data$unit, data$AvailbleLeft)
  leftwarn1=aggregate(data$AvailableLeft ~ data$engine + data$unit, data =    df11, sum) #Counting number of "1s" per unit per engine
  leftwarn10 = count(data$AvailableLeft == 0, c("data$engine","data$unit")) #counting number of "1 and 0" per unit per engine
  </code></pre>