title: Choosing values on a variable depend on other variables
body: <p>In this dataframe, for each unique acount I have many unique user. For each acount I have a cost variable by month. Here I want to create a new variable cost2 for example where I keep only cost respecting the following condition :
  * for each month, I want to keep only cost for only one account and others equal to zero   </p>
  
  <pre><code>acount &lt;- c(1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4, 1)
  user &lt;- c(1:12, 2)
  month &lt;- c(201501, 201501, 201502, 201503, 201503, 201501, 
             201501, 201501, 201502, 201503, 201503, 201501, 201505)
  cost &lt;- c(30, 30 , 25, 40 , 40, 20, 20, 17, 17, -20, 18, 13, 0)
  
  df &lt;- data.frame(acount, user, month, cost)
  </code></pre>
  
  <p>For example for the account 1, I want to keep in cost2 the followings values : 30, 25, 0</p>
  
  <p>I'm trying to do it with the ifelse statement but I'm stuck ...
  Thank you </p>