Let's say we have a following dataframe named df
:
Country GDP/capita HDI
1 67426 0.92
2 46827 0.92
4 47223 0.89
3 52559 0.94
Let's also say we have a numeric named vector vec
with values 1
, 2
, 3
and 4
and names USA
, UK
, Germany
and France
.
Given those two objects, what is the fastest way to make the dataframe look like this:
Country GDP/capita HDI
USA 67426 0.92
UK 46827 0.92
France 47223 0.89
Germany 52559 0.94
(Note that the order of the vector is 1, 2, 3, 4, while the order in the dataframe is 1, 2, 4, 3).
Tidyverse solutions preferred!