I have a data frame that looks like this:
Time Y
1 2
1 3
1 2
2 5
2 7
2 5
3 10
3 9
3 8
And I'd like to create something that looks like
Time R1 R2 R3
1 2 3 2
2 5 7 5
3 10 9 8
I have to keep the time column for further regression analysis. I can accomplish this by using Time2=Time and using Time2 for names_from argument. However, I get errors along the lines of:
> foo
  Time  Y Time2
1    1  2     1
2    1  3     1
3    1  2     1
4    2  5     2
5    2  7     2
6    2  5     2
7    3 10     3
8    3  9     3
9    3  8     3
> pivot_wider(foo, names_from=Time2, values_from=Y)
# A tibble: 3 x 4
   Time `1`       `2`       `3`      
  <dbl> <list>    <list>    <list>   
1     1 <dbl [3]> <NULL>    <NULL>   
2     2 <NULL>    <dbl [3]> <NULL>   
3     3 <NULL>    <NULL>    <dbl [3]>
Warning message:
Values in `Y` are not uniquely identified; output will contain list-cols.
* Use `values_fn = list(Y = list)` to suppress this warning.
* Use `values_fn = list(Y = length)` to identify where the duplicates arise
* Use `values_fn = list(Y = summary_fun)` to summarise duplicates 
I'm not sure what I'm doing wrong.