If you're not experienced with R (or programming in general) avoid substitute
, deparse
, eval
, etc. They are rarely necessary.
DT <- data.table(f = c("a", "b", "c"), num = rpois(6, 30))
DT[["f"]] <- factor(DT[["f"]])
get_levels <- function(data,fac){
levels(data[[fac]])
}
get_levels(DT,'f')
And don't call your column factor
. That's a function, and it's just confusing.