Create Group-Specific Variables

Learn how to create group-specific variables, recode variables, rename variables, and create variable labels.

We often need to create group-specific or by-group variables. The world average economic growth rate is a good example of a by-group variable. It’s an average of the growth rates of all countries by each year, which allows us to compare a country’s own growth rate with that of the world economy. Below, we demonstrate how to create a by-group variable in R using the by() function.

Get hands-on with 1200+ tech skills courses.