Snippets

Juan Martín Barrios Vargas Create Train-Test set in R

Created by Juan Martín Barrios Vargas
1
2
3
4
5
6
7
8
splitdf <- function(dataframe, ratio=0.66, seed=NULL) {
    if (!is.null(seed)) set.seed(seed)
    index <- 1:nrow(dataframe)
    trainindex <- sample(index, trunc(length(index)*ratio))
    trainset <- dataframe[trainindex, ]
    testset <- dataframe[-trainindex, ]
    list(trainset=trainset, testset=testset)
}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.