I have a dataframe that looks something like this
NUM <- c("45", "45", "45", "45", "48", "50", "66", "66", "66", "68")
Type <- c("A", "F", "C", "B", "D", "A", "E", "C", "F", "D")
Points <- c(9.2,60.8,22.9,1012.7,18.7,11.1,67.2,63.1,16.7,58.4)
df1 <- data.frame(NUM,Type,Points)
df1:
+-----+------+--------+
| 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 |
+-----+------+--------+
I am trying to obtain an output that takes the rows in type column to convert it to individual columns.
Desired Output:
+-----+----------+----------+----------+----------+----------+----------+
| 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 |
+-----+----------+----------+----------+----------+----------+----------+
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.