Skip to content
Prev 246002 / 398503 Next

access a column of a dataframe without qualifying the name of the column

On Dec 29, 2010, at 7:11 PM, John Sorkin wrote:

            
Not sure what the verb "qualify" means in programming. Quoting?
> df <- data.frame(x=1:10,y=11:20)
 > test <- function(column,dat) { print(colname <-  
deparse(substitute(column)))
+  dat[[colname]]
+ }
 >
 > test(x,df)
[1] "x"
  [1]  1  2  3  4  5  6  7  8  9 10
 >