Skip to content

Instantly share code, notes, and snippets.

@toyeiei

toyeiei/.R

Last active Nov 13, 2018
Embed
What would you like to do?
split dataset into train and test in R
# install new package
install.packages("mlbench")
library(mlbench)
# load data into R
data(BreastCancer)
# review dataset
str(BreastCancer)
head(BreastCancer)
summary(BreastCancer)
# remove ID column
BreastCancer$Id <- NULL
# remove missing values
BreastCancer <- BreastCancer[complete.cases(BreastCancer),]
# prepare dataset
# split data into 70% train and 30% test sets
set.seed(123)
idx <- sample(nrow(BreastCancer), 0.7*nrow(BreastCancer))
train_df <- BreastCancer[idx, ]
test_df <- BreastCancer[-idx, ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.