October 2017
Beginner to intermediate
572 pages
26h 1m
English
You can combine the split process of the training and testing datasets into the split.data function. Therefore you can easily split the data into the two datasets by calling this function and specifying the proportion and seed in the parameters:
> split.data = function(data, p = 0.7, s = 666){
+ set.seed(s)
+ index = sample(1:dim(data)[1])
+ train = data[index[1:floor(dim(data)[1] * p)], ]
+ test = data[index[((ceiling(dim(data)[1] * p)) + 1):dim(data)[1]], ]
+ return(list(train = train, test = test))
+ }
Read now
Unlock full access