How to split train test dataset in R

In [2]:
# -----------------------------------------------------------------
# How to split train test dataset in R 
# -----------------------------------------------------------------
# load the library
library(corrgram)
library(mlbench)
library(caret)

# load the data
data(iris)
DataSet <- as.data.frame(iris)

dim(DataSet)
sapply(DataSet, class)

# Pre-Processing of DataSet i.e. train : test split
train_test_index <- createDataPartition(DataSet$Species, p=0.67, list=FALSE)
training_dataset <- DataSet[train_test_index,]
testing_dataset <- DataSet[-train_test_index,]

# dimention of train test dataset 
dim(training_dataset)
dim(testing_dataset)
  1. 150
  2. 5
Sepal.Length
'numeric'
Sepal.Width
'numeric'
Petal.Length
'numeric'
Petal.Width
'numeric'
Species
'factor'
  1. 102
  2. 5
  1. 48
  2. 5
In [ ]: