define $ right parameter with a variable in R [duplicate]

Use [[ instead of $. x$y is short hand for x[["y"]].

my_helper <- function (my_param) {
  levels(diamond[[my_param]])
}
my_helper("cut")

Leave a Comment