How can I call matrix$col, inside a function? The matrix name is one of the variables of the function, while the column name I get by assuming that it should have a certain characters. something like this function(matrix){ colname=as.name(grep("[A-T a-t]ting",colnames(matrix),value=TRUE)) output=2*(matrix$colname) return(output) } The name of the column is Testing.