R code: classification and cross-validation