Created
May 11, 2015 16:05
-
-
Save estebanz01/340cb56b6303882f61c7 to your computer and use it in GitHub Desktop.
Split function to divide data frames in trainset & testset.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
splitdf <- function(dataframe, seed=NULL) { | |
if (!is.null(seed)) set.seed(seed) | |
index <- 1:nrow(dataframe) | |
trainindex <- sample(index, trunc(length(index)/2)) | |
trainset <- dataframe[trainindex, ] | |
testset <- dataframe[-trainindex, ] | |
list(trainset=trainset,testset=testset) | |
} | |
#Source of this function: http://www.gettinggeneticsdone.com/2011/02/split-data-frame-into-testing-and.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment