title: Transforming data in specific rows and columns inside a data frame in R
body: <p>I have a data frame</p>
  
  <pre><code>Name   M0  M1 M2 M3 M4 M5  
  ABC    4   4  3  4  33 22
  XYZ    3   5  6  22  1 33
  RTF    3   7  33 2   4  0
  hdj    32  3  9  3   1  3
   .
   .
  Tim    4   4   0  3  3  1
  </code></pre>
  
  <p>I would like to add NA or Null values based on the following patern. 2nd row all column values to remain. But 3rd row the last colum value to be made NULL or NA. 4th row last two column values</p>
  
  <pre><code>Name   M0  M1 M2 M3 M4 M5  
  ABC    4   4  3  4  33 22
  XYZ    3   5  6  22  1 NA
  RTF    3   7  33 2  NA NA
  hdj    32  3  9  NA NA  NA
  .
  .
  tim    3   NA NA NA NA NA
  </code></pre>
  
  <p>This is my attempt</p>
  
  <pre><code>    # getting the maximum rows and cols
      rows&lt;-nrow(df)
      cols&lt;-ncol(df)
  
      for (i in 3:rows) {
  
    df[i,cols:cols-i-1]&lt;-NULL  
  
  }
  </code></pre>
  
  <p>Apology for how basic this is. But just one of those days! It would useful to know the  multiple ways of achieving this. Personally a fan dplyr package.</p>