I would like to analyze the data set data(wine) which is available in the R package gclus.
How can I split the data set according to the proportions 70:30 into a training and a test set?
>Solution :
You can split your data like this:
library(gclus)
data("wine")
sample_size <- floor(0.70 * nrow(wine))
set.seed(123)
train_index <- sample(seq_len(nrow(wine)), size = sample_size)
train <- wine[train_index, ]
test <- wine[-train_index, ]
Checking the sizes of the datasets:
> nrow(wine)
[1] 178
> nrow(train)
[1] 124
> nrow(test)
[1] 54