Awesome! But suppose we wanted to create column names based on certain values? For example, say we wanted to have a column for each year in our population dataset, and we wanted it named
year_<year name>. This column name should increase with each year:
year_2010 and so on.
To do so, we'd simply use the sep argument with
spread(). This is what it looks like:
spread(population, year, pop, sep = "_")
This creates new column names based on the original column name (
year) and levels made up from values in that column (here, the various years). This will give us columns named