## EXAMPLE 1
x <- sample(c(1, 3, 4), size = 20, replace = TRUE)
table(x)
sampcla(x, m = 2)
s <- sampcla(x, m = 2)$test
x[s]
sampcla(x, m = c(1, 2, 1))
s <- sampcla(x, m = c(1, 2, 1))$test
x[s]
y <- rnorm(length(x))
sampcla(x, y, m = 2)
s <- sampcla(x, y, m = 2)$test
x[s]
## EXAMPLE 2
data(cassav)
X <- cassav$Xtrain
y <- cassav$ytrain
N <- nrow(X)
fm <- pcaeigenk(X, nlv = 10)
z <- stats::kmeans(x = fm$T, centers = 3, nstart = 25, iter.max = 50)
x <- z$cluster
z <- table(x)
z
p <- c(z) / N
p
psamp <- .20
m <- round(psamp * N * p)
m
random_sampling <- sampcla(x, m = m)
s <- random_sampling$test
table(x[s])
Systematic_sampling_for_y <- sampcla(x, y, m = m)
s <- Systematic_sampling_for_y$test
table(x[s])
Run the code above in your browser using DataLab