title: Conditional mean statement
body: <p>I have a dataset named <code>bwght</code> which contains the variable <code>cigs</code> (cigarattes smoked per day)</p>
  
  <p>When I calculate the mean of <code>cigs</code> in the dataset <code>bwght</code> using:
  <code>mean(bwght$cigs)</code>, I get a number 2.08.</p>
  
  <p>Only 212 of the 1388 women in the sample smoke (and 1176 does not smoke):</p>
  
  <p><code>summary(bwght$cigs&gt;0)</code> gives the result:    </p>
  
  <pre><code>Mode      FALSE    TRUE    NA's 
  logical    1176     212       0
  </code></pre>
  
  <p>I'm asked to find the average of <code>cigs</code> among the women who smoke (the 212).</p>
  
  <p>I'm having a hard time finding the right syntax for excluding the non smokers = 0
  I have tried:</p>
  
  <ul>
  <li><p><code>mean(bwght$cigs| bwght$cigs&gt;0)</code></p></li>
  <li><p><code>mean(bwght$cigs&gt;0 | bwght$cigs=TRUE)</code></p></li>
  <li><p><code>if (bwght$cigs &gt; 0){
  sum(bwght$cigs)
  }</code></p></li>
  <li><p><code>x &lt;-as.numeric(bwght$cigs, rm="0");
  mean(x)</code></p></li>
  </ul>
  
  <p>But nothing seems to work!  Can anyone please help me??</p>