Suppose I have the following data.frame:
a <- data.frame(group=c(3, 3, 3, 5, 5, 5), code=c(1, 2, 3, 1, 2, 3), val=c(10, 20, 30, 40, 50, 60), val2=c(100, 200, 300, 400, 500, 600))
a
    group code val val2
1     3    1  10  100
2     3    2  20  200
3     3    3  30  300
4     5    1  40  400
5     5    2  50  500
6     5    3  60  600
I would like to get the following data.frame:
  group  "1.val" "2.val" "3.val" "1.val2" "2.val2" "3.val2"
1     3     10     20       30      100      200      300
2     5     40     50       60      400      500      600
The column names are not correct in the duplicated post.
NOTE: I would prefer a base-R solution but other ideas would be interesting to see
 
     
    