How to subset a data set based on column names

Aside from the provided perfectly working solution in base-r, you may want consider the tidyverse package as part of your toolkit:

The tidyverse is a coherent system of packages for data manipulation, exploration and visualization that share a common design philosophy.

For instance, in the following chapter - of the excellent online free R for Data Science book - the select() function is introduced and several approaches of selecting your column variables are described.

This book is definitely worthwhile to get you started.

HTH as well