Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Create new variables
5. Function transmute()
Grouping and statistical functions
Joining datasets


Maybe we want to keep only the new column we've made by calculating the results from other columns. We could combine mutate() with select() to do this, or we could choose the easy way and just use the transmute() function. This computes a new column and then drops all the others. To get only the newly created density column, we'd write:

transmute(countries, density = population / area)


Use transmute() to create a new column named rural_pop that contains the proportion of a country's rural population to the country's total population. Use the population and urban_population columns.

Stuck? Here's a hint!

The rural proportion is inverse to the urban proportion, so just type:

transmute(countries, rural_pop = 1 - (urban_population / population))