Implementing cross validation via R