I am attempting to split my data into three separate dataframes (train, test, validate) using a function but it is not returning the results I require.
This is my function:
splitData <- function(type) {
set.seed(1337)
rowTrain <- createDataPartition(y = cleaned.data$CHURN, p = 0.7, list = FALSE)
bufferDF <- cleaned.data[-rowTrain,]
rowTest <- createDataPartition(y = cleaned.data$CHURN, p = 0.50, list = FALSE)
if(type == "train") {cdTrain <- cleaned.data[rowTrain,]}
if(type == "train") {cdTrain}
if(type == "test") {cdTest <- cleaned.data[rowTest,]}
if(type == "test") {cdTest}
if(type == "validate") {cdValidate <- bufferDF[-rowTest,]}
if(type == "validate") {cdValidate}
}
Could you please shine some light on where I am going wrong?
Cheers
ifstatements for each type? Why not just do, e.g.,if(type=="train") {cdTrain<-cleaned.data[rowTrain,]; cdTrain}?cdTrain <- splitData(train)to no avail. Also have triedsplitData("train")andsplitData(type = "train"). Where am I going wrong?