To access a certain column in a data frame we use $, so data$variable gives us the column with the column name variable. Now suppose I have a string variable var called "variable", how do I access the column using var instead of variable? Saying data$var returns NULL. I can't use data[[var]] either because I need to do a filter(data, var %in% variable). This cannot be fixed by filter_.
            Asked
            
        
        
            Active
            
        
            Viewed 1,199 times
        
    0
            
            
         
    
    
        JJTsai
        
- 51
- 5
- 
                    @Andrew Taylor See my edit – JJTsai Jun 07 '16 at 18:29
- 
                    Based on edit OP isn't asking about base but rather about `dplyr`. See the [dplyr vignette on nonstandard evaluation](https://cran.r-project.org/web/packages/dplyr/vignettes/nse.html). And I'm sure we can find a more appropriate dupe. – Gregor Thomas Jun 07 '16 at 18:33
1 Answers
0
            
            
        Use data[, var] for a vector of data$variable or data[var] for data.frame containing the one column variable
 
    
    
        Andrew Taylor
        
- 3,438
- 1
- 26
- 47