Advertisement
Guest User

Untitled

a guest
May 25th, 2015
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. library(magrittr)
  2.  
  3. # The data
  4. sal_dat <- c(25, 15, 20, 25, 18, 12, 24, 30, 15, 20, 10, 10, 11, 14, 22, 16)
  5. salary <- sal_dat * 1000
  6.  
  7. # Function for systematic sampling
  8. sys_sample <- function (df, r, n) {
  9. k <- (df %>% length) / n
  10.  
  11. b <- numeric(); a <- r
  12. b[1] <- a
  13.  
  14. for (i in 2:n) {
  15. a <- a + k
  16. if (a > (df %>% length)) {
  17. a <- a - (df %>% length)
  18. }
  19. b[i] <- a
  20. }
  21.  
  22. return (list(Data = df[b], Index = b, K = k))
  23. }
  24.  
  25. # Do the sampling for random start,
  26. # r = 2, and number of sample, n = 4
  27. sys_sample(salary1, r = 2, n = 8)
  28.  
  29. # OUTPUT
  30. $Data
  31. [1] 15000 25000 12000 30000 20000 10000 14000 16000
  32.  
  33. $Index
  34. [1] 2 4 6 8 10 12 14 16
  35.  
  36. $K
  37. [1] 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement