Mulai sekarangMulai gratis

WHO obesity vs. life expectancy

You've been given a sample of WHO data (who_df) with obesity percentages and life expectancy data per country, year, and sex. You want to visually inspect the correlation between obesity and life expectancy.

However, the data is very messy with four variables hidden in the column names. Each column name is made up of three parts separated by underscores: Values for the year, followed by those for sex, and then values for either pct.obese or life.exp. Since the third part of the column name string holds two variables you'll need to use the special ".value" value in the names_to argument.

You'll pivot the data into a tidy format and create the scatterplot.

The ggplot2 package has been pre-loaded for you.

Latihan ini merupakan bagian dari kursus

Reshaping Data with tidyr

Lihat Kursus

Latihan interaktif langsung praktik

Cobalah latihan ini dengan melengkapi kode contoh ini.

who_df %>% 
  # Put each variable in its own column
  ___(
    ___,
    names_to = ___,
    names_sep = "_",
    names_transform = ___(___ = ___)
  )
Edit dan Jalankan Kode