Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I want to rename a variable in a column

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)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading