Should columns with close to zero variance be removed before or after one hot encoding? I've been using R and the caret package since a while. The caret package provides a function to reduce the number of variables - nearZeroVar() wherein variables that have close to zero variance are returned and one can remove them from the dataframe

Caret also provides another function dummyVars that converts factors to dummy variables.

Now my question is - what should the order of using the two be? Should the features with near zero variance be thrown out and then converted to dummies or should it be the other way around? I have a feeling that the order matters because in some cases dummy variables might have a lot of zeros but still be important.
I think 1st you need to remove the columns with near to zero variance(assuming that they are not nominal variables), only if you have more variables as the computation time can be reduced.

Let us consider a scenario where there are 2 columns col1, col2 and you checked for variance then col1 had 0.003 variance and col2 had 0.5 var. once you apply the function nearZeroVar(), it removes col1, you need to hot-encode only 1 variable.

By that you can save time and your computer performance won't be effected.