title: R: Pivot the rows into columns and use N/A's for missing values
body: <p>I have a dataframe that looks something like this </p>
  
  <pre><code>NUM &lt;- c("45", "45", "45", "45", "48", "50", "66", "66", "66", "68")
  Type &lt;- c("A", "F", "C", "B", "D", "A", "E", "C", "F", "D")
  Points &lt;- c(9.2,60.8,22.9,1012.7,18.7,11.1,67.2,63.1,16.7,58.4)
  
  df1 &lt;- data.frame(NUM,Type,Points)
  </code></pre>
  
  <p>df1: </p>
  
  <pre><code>+-----+------+--------+
  | NUM | TYPE | Points |
  +-----+------+--------+
  |  45 | A    | 9.2    |
  |  45 | F    | 60.8   |
  |  45 | C    | 22.9   |
  |  45 | B    | 1012.7 |
  |  48 | D    | 18.7   |
  |  50 | A    | 11.1   |
  |  66 | E    | 67.2   |
  |  66 | C    | 63.1   |
  |  66 | F    | 16.7   |
  |  65 | D    | 58.4   |
  +-----+------+--------+
  </code></pre>
  
  <p>I am trying to obtain an output that takes the rows in type column to convert it to individual columns. </p>
  
  <p>Desired Output:</p>
  
  <pre><code>+-----+----------+----------+----------+----------+----------+----------+
  | NUM | Points.A | Points.B | Points.C | Points.D | Points.E | Points.F |
  +-----+----------+----------+----------+----------+----------+----------+
  |  45 | 9.2      | 1012.7   | 22.9     | N/A      | N/A      | 60.8     |
  |  48 | N/A      | N/A      | N/A      | 18.7     | N/A      | N/A      |
  |  50 | 11.1     | N/A      | N/A      | N/A      | N/A      | N/A      |
  |  66 | N/A      | N/A      | 63.1     | N/A      | 67.2     | 16.7     |
  |  65 | N/A      | N/A      | N/A      | N/A      | 58.4     | N/A      |
  +-----+----------+----------+----------+----------+----------+----------+
  </code></pre>
  
  <p>I tried using melt(df1) but doing it wrongly since the values in the rows are the NUM values rather than points. Kindly let me know how I could go about solving this. </p>