this question has answer here:
i writing function must divide whole set 2 smaller ones @ random. size of set determined user. try way
number <- function(z,y,p){ indeks <-split(z$y,sample(rep(1:2), c(p, z$y-p))) train <- z[indeks,] test <- z [-indeks, ] result <- list(test, train) list(result) } number(z=lipiec , y=vii, p=200)
however, following error pops up
error in sample.int(length(x), size, replace, prob) : cannot take sample larger population when 'replace = false'
the structure of file trying divide int. , there 574 lines. value 200 not greater whole sample. 2 randomly split sets, 1 of them (test) have 200 elements, , other (train) rest of base set. have idea doing wrong?
*****edit**** after modification did follows:
number <- function(z,y,p){ df <- as.data.frame(z$y) indeks <-split(df, sample(nrow(df))<=p) train <- indeks$ test <- indeks$ str(test)} number(z=lipiec , y=vii, p=200)
now not know should assign test , train assign each of them 1 of parts of collection. have idea?
myfun <- function(df, n) { split(df, sample(nrow(df))<=n) } set.seed(1) myfun(mtcars,10)
Comments
Post a Comment