Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(magrittr)
- # The data
- sal_dat <- c(25, 15, 20, 25, 18, 12, 24, 30, 15, 20, 10, 10, 11, 14, 22, 16)
- salary <- sal_dat * 1000
- # Function for systematic sampling
- sys_sample <- function (df, r, n) {
- k <- (df %>% length) / n
- b <- numeric(); a <- r
- b[1] <- a
- for (i in 2:n) {
- a <- a + k
- if (a > (df %>% length)) {
- a <- a - (df %>% length)
- }
- b[i] <- a
- }
- return (list(Data = df[b], Index = b, K = k))
- }
- # Do the sampling for random start,
- # r = 2, and number of sample, n = 4
- sys_sample(salary1, r = 2, n = 8)
- # OUTPUT
- $Data
- [1] 15000 25000 12000 30000 20000 10000 14000 16000
- $Index
- [1] 2 4 6 8 10 12 14 16
- $K
- [1] 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement