Question: 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.

Answer: 
You can use the constructor that accepts a range of iterators:

```
std::vector<uint8>(std::begin(signed_vec), std::end(signed_vec));

```

That said, in case you don't actually need a `std::vector<uint8>` object, but rather simply want to read a range of unsigned integers, you can reinterpret them instead:

```
uint8* ptr_beg = reinterpret_cast<uint8>(signed_vec.data());
uint8* ptr_end = ptr_beg + signed_vec.size();

```

Conversion between unsigned and signed versions of the same integer size is one of the rare cases where reinterpretation is well defined.
You can traverse through each element and cast/push back to the new vector:

```
std::vector<int8> vec_int8 = returnedFromApi(); // assume it is filled
std::vector<uint8> vect_uint8;
for(int item = 0; item < vec_int8.size(); ++item)
{
  vect_uint8.push_back(static_cast<uint8>(vec_int8[item]));
}

```