You can create a vector of columns and then use each element from that vector to access the data from each column. You do not need to use the $ operator.
Here is an example:
df <- data.frame(x=c(10,20,30,40), y=c(1,2,3,4),z=c(11,12,13,14), w=c(11,22,33,44))
cols <- colnames(df)
for (col in cols){
print(df[[col]])
}
So, instead of using the $ operator, I am using python style [[]] to access the column at run time.
The above code returns the following output:
[1] 10 20 30 40
[1] 1 2 3 4
[1] 11 12 13 14
[1] 11 22 33 44