Random forest cross validation for feature selection, imbalanced datasets I have an 5297X26 imbalanced dataset, the class1 has 588 samples and class2 has 4709 samples. I used the following code to perform random forest:
rfp<-randomForest(label~.,data=data,importance=TRUE,proximity=TRUE,replace=TRUE,sampsize=c(588,588))    

Thus I could solve the imbalanced problem by selecting 588 samples from each class in each iteration. But I also want to perform cross validation for feature selection. The function I plan to use is      rfcv    .I tried to add     sampsize=c(588,588)    to the function but it didn't work. How to perform the sampling in this function? 
 A: Your class1 and class2 summed 588 and 4709 do not add up to 5267 but 5297. 
But assuming you have a 5297x26 set of regressors allows me to estimate the random forrest by the call you posted
data <- data.frame(matrix(rnorm(5297*26), ncol=26), 
                   label=c(rep('class1', 588), 
                           rep('class2', 4709)))
randomForest(label~., data=data,importance=TRUE, proximity=TRUE, 
             replace=TRUE, sampsize=c(588,588))    

perhaps you could use stratified sampling with constant fractions of each class so if you would want 2/3 of each class you could use sampsize=c(392, 2472)
A: Any method that requires that you discard data in order to use it is defective.  You may have been tempted to do this because you intend to use a discontinuous improper accuracy scoring rule such as proportion "classified" "correctly".  That particular accuracy score is arbitrarily manipulated by the prevalence of positive cases, unlike the concordance probability ($c$-index; ROC area) and other measures of predictive discrimination.
