I'm trying to do one hot encoding on a data set containing 4 categorical features in R. Unique levels per feature: 400, 60, 6, 5, respectively. I get the following error during the first call to the ohe function (acm.disjonctif):
Error in sort.list(y) : 'x' must be atomic for 'sort.list' Have you called 'sort' on a list?
I can't do sorting on a per column basis because it will remove the data relationship between columns. What am I missing in understanding? I searched on the web but couldn't find anything helpful.
Here is the code I'm running in RStudio:
ohe_feats = c('RSN_CD', 'RSN_CAT', 'ELIG_SYS_CD', 'PROD_CD')
for (f in ohe_feats) {
df_all_dummy = acm.disjonctif(as.factor(nodups[f])) # package = ade4
nodups[f] = NULL
nodups = cbind(nodups, df_all_dummy)
}
nodups
? And any particular reason you doing this in a loop and then cbinding the results together? $\endgroup$