0

My data set looks like this:

Col1 Col2
AA    ID1
BB    ID2
CC    ID3
BB    ID4
AA    ID5

I would like to separate values in Col2 based on the categories of Col1. The final product would look like this:

AA   BB  CC
ID1  ID2 ID3
ID5  ID4 NA

I have been trying different for loops without success. I am thinking there must be a much easier way. Any chance someone would know a simple trick?

Thank you!

AP38
  • 159
  • 7
  • 1
    You can use `dcast` or `spread` – akrun Jan 28 '19 at 18:23
  • 1
    Thank you, spread works. I did not know that function! For instance: data %>% spread(Col1, Col2) – AP38 Jan 28 '19 at 18:49
  • Apologize for duplicating that question. I did not find it until @akrun pointed it. Feel free to close the question if needed – AP38 Jan 28 '19 at 18:53
  • Its okay. I tagged it as dupe. It is easier to find answers on google when there are more dupe links – akrun Jan 28 '19 at 18:54

0 Answers0