title: Assigning value to a specific column and row in R
body: <p>I have a data frame as below. </p>
  
  <pre><code>Name Amount Subscriptionperiod(Months)  Subscriptionstart (Month)
  Tom  300    3                             0
  Tom  100    3                             2
  Jim  500    5                             0
  Jim  600    3                             1
  </code></pre>
  
  <p>I would like to arrange the data like below. For example Tom paid 300$ for 3 months in one transaction. And in a second transaction 2 months later he paid additional 100$ for 3 months. </p>
  
  <p>Similarily for Jim. </p>
  
  <pre><code>Name   M0   M1  M2   M3  M4  M5  M6
  Tom    300 300  300  0   0   0   0
  Tom    0    0   100  100 100 0   0
  Jim    500 500  500  500 500 0   0
  Jim    0   600  600  600 0   0   0
  </code></pre>
  
  <p>I'm not able to transform. I use the code below to do the first part. But how do I create a second row where the value starts from M2 in the case of Jim. 100$ to start from M2 and continue till M4.</p>
  
  <pre><code>for(i in 0:6) df &lt;- within(df,assign(paste0("M",i),ifelse((Subscriptionperiod&gt;i),amount,0)))
  </code></pre>
  
  <p>The code above gives the following output which is not what I want. Help would appreciated.</p>
  
  <pre><code>     Name   M0   M1  M2   M3  M4  M5  M6
      Tom    300 300  300  0   0   0   0
      Tom    100  100 100  0   0   0   0
      Jim    500 500  500 500 500  0   0 
      Jim    600  600  600 0   0   0   0
  </code></pre>