-1

I know that this must be answered somewhere, but I cant seem to find a solution.

I have the following

id qid val
A   X   5
A   Y   4
A   Z   3
B   X   2
B   Y   1

I would like it to look like this

id  X Y Z
A   5 4 3 
B   2 1 NA 

Where each id has a unique column.

Here is the data for easy copy-paste

tribble(
  ~id, ~qid, ~val,
   "A",  "X",   5,
   "A",  "Y",   4,
   "A",  "Z",   3,
   "B",  "X",   2,
   "B",  "Y",   1
)
Alex
  • 2,603
  • 4
  • 40
  • 73

1 Answers1

0

dcast from reshape2

dcast(dat, id ~ qid, value.var = "val")