R Conditional Regression with Multiple Conditions

Solution 1:

The problem is:

df$2010

If your data really has a column named 2010, then you need backticks around it:

df$`2010`

And in your subset, don't specify df twice:

subset(df, msa == 1, `2010` == 1)

In general it's better if column names don't start with digits. It's also best not to name data frames df, since that's a function name.