I have this table here, ordered by country:
country | city |
---|---|
Canada | Montreal |
Canada | Toronto |
France | Paris |
France | Lyon |
Australia | Melbourne |
Japan | Nagoya |
I want to create an index col of countries, something like:
index | country | city |
---|---|---|
1 | Canada | Montreal |
1 | Canada | Toronto |
2 | France | Paris |
2 | France | Lyon |
3 | Australia | Melbourne |
4 | Japan | Nagoya |
I know I can create another df with distinct countries and then merge. I'm looking for something that can be includide in a pipeline.
Here is a reproductible code:
tibble(country = c('Canada','Canada','France','France','Australia','Japan'),
city = c('Montreal','Toronto','Paris','Lyon','Melbourne','Nagoya'))
Thanks!