How can I access the levels of the factors of a data.frame in Rcpp when it is passed as an argument from R?
问题 I have the following data.frame df1 with factor fac1 that I have created in R and I pass it as an argument in a Rcpp function. The requested task is to get all the factor levels inside an Rcpp function and use them. fac1 <- factor(x = sample(x = 1:5,size = 100,replace = T),labels = paste0("D",1:5)) var1 <- sample(x = 1:20,size = 100,replace = T) fac2 <- factor(x = sample(x = 1:12,size = 100,replace = T),labels = paste0("M",1:12)) df1 <- data.frame(fac1,var1,fac2) 回答1: After some research I