Is it important in R to convert “integer” variables (with 0 or 1 values) to factors? I am working on a high-dimensional dataset (1776 variables). When I read the csv file, R loads variables (with 0 or 1 values) as class of "integer".
Is it important to convert these variables to factors before building predictive models (e.g gbm, randomForest, SVM, etc.)?
What if I want to use PCA to reduce the dimension, is it correct to keep these variables as "integer"? (since PCA does not work with factor variables).
 A: R's factor() command is just a shortcut to having to manually create the indicator variables for each (except one) value of a categorical variable. Since you are starting with indicator variables, you don't need to do anything.
A: But be careful if the values you mentioned are your output values. If you use for example the caret package, which describes itself as "a set of functions that attempt to streamline the process for creating predictive models." So it is basically a layer on top of many different machine learning packages in R. 
If you use the train method and choose for example a SVM algorithm and your output values are integer values, the algorithm will handle it as a regression problem automatically and not as a classification problem. This will probably decrease the performance of the algorithm including accuracy and sensitivity.
So if these values are your output or y values and your dataset belongs to a classification problem, transform the values to factors. If the values are "just" x or feature values I totally agree with Andy and you can leave them as integers.
Regards
A: Take a look at the R ade4 package's dudi.mix and dudi.hillsmith functions.  These are natural extensions of PCA for mixed numerical and categorical data.  You'll get different (better!) results using these functions if you first convert an integer column containing a categorical variable into a factor.  From the documentation:  "dudi.hillsmith allow to use various row weights, while dudi.mix deals with ordered variables.  The principal components of this analysis are centered and normed vectors maximizing the sum of squared correlation coefficients with quantitative variables [and] correlation ratios with factors."  See https://cran.r-project.org/web/packages/ade4/ade4.pdf. 
