June 2017
Beginner to intermediate
576 pages
15h 22m
English
Now that we are finished with our transformations, we will create the training and test data frames. We will perform a 50/50 split between training and test:
# Take a sample of full vectornrow(OnlineRetail) > [1] 536068 pctx <- round(0.5 * nrow(OnlineRetail))set.seed(1)# randomize rowsdf <- OnlineRetail[sample(nrow(OnlineRetail)), ]rows <- nrow(df)OnlineRetail <- df[1:pctx, ] #training setOnlineRetail.test <- df[(pctx + 1):rows, ] #test setrm(df)# Display the number of rows in the training and test datasets.nrow(OnlineRetail) > [1] 268034 nrow(OnlineRetail.test) > [1] 268034