Do not use $in this case; use instead [. Here is a minimal example (if I understand what you are trying to do).
mydf <- data.frame(A = 1:2, B = 3:4)
mydf
x <- c("A", "B")
x
mydf[, x[1]]
mydf[, x[1], drop = FALSE]
, R Inferno. 8: ", , ", " ".... The main difference is that $ does not allow computed indices, whereas [[ does. ?Extract.
, - , , , [row, column] ( $ matrix).