title: How to convert a string to a variable name in R
body: <p>To access a certain column in a data frame we use <code>$</code>, so <code>data$variable</code> gives us the column with the column name <code>variable</code>. Now suppose I have a string variable <code>var</code> called <code>"variable"</code>, how do I access the column using <code>var</code> instead of <code>variable</code>? Saying <code>data$var</code> returns <code>NULL</code>. I can't use <code>data[[var]]</code> either because I need to do a <code>filter(data, var %in% variable)</code>. This cannot be fixed by filter_.</p>