0

How do i rename a country within my countries column, every time i get Russian Federation i want to to be renamed to Russia. Eg below;

gdp = filter(gdp, Country == 'Russian Federation')
> gdp
# A tibble: 1 × 3
  Country             Year    GDP
  <chr>              <dbl>  <dbl>
1 Russian Federation  2016 24072.

Tried this and i think im close but cant quite think what i need to change;

gdp = gdp %>%
  rename(gdp, Country == 'Russian Federation' == Russia)
deschen
  • 10,012
  • 3
  • 27
  • 50
Joe
  • 87
  • 7

1 Answers1

3

rename is for renaming the whole column, i.e. its name. What you want is to change some values of a column.

Try

library(tidyverse)
gdp %>%
  mutate(Country = if_else(Country == 'Russian Federation', 'Russia', Country))
deschen
  • 10,012
  • 3
  • 27
  • 50
  • Is there a way i can do 2 counties in the same line? or would i have to call mutate again like... mutate(Country = if_else(Country == United Kingdom of Great Britain and Northern Ireland = 'United Kingdom', Country)) – Joe Feb 22 '22 at 23:02
  • 1
    Please check the help function for `case_when`, which allows to do specify several conditions in one command. – deschen Feb 22 '22 at 23:12