Home > OS >  I want to rename a value of a column
I want to rename a value of a column

Time:02-23

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)

CodePudding user response:

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))
  •  Tags:  
  • r
  • Related