IT-Academy

Sample a pocetnosti

Apr 27th, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 0.65 KB | None | 0 0
  1. print(sample(1:3))
  2. print(sample(1:3, size=3, replace=FALSE))  # same as previous line
  3. print(sample(c(2,5,3), size=4, replace=TRUE))
  4. print(sample(1:2, size=10, prob=c(1,3), replace=TRUE))
  5.  
  6. print(sample(c(2,5,3), size=3, replace=FALSE))
  7. print(sample(c(2,5,3), size=3, replace=TRUE))
  8.  
  9. barplot(table(sample(1:3, size=1000, replace=TRUE, prob=c(.30,.60,.10))))
  10.  
  11. install.packages("plyr")
  12. library(plyr)
  13. ds <- matrix(c(sample(1:3,6,replace=T),sample(4:6,6,replace=T)),ncol=2)
  14. #ds is the generated dataset, your data would go here
  15. apply(ds,2,count)
  16.  
  17. # [[1]]
  18. # x freq
  19. # 1 1    1
  20. # 2 2    3
  21. # 3 3    2
  22. # [[2]]
  23. # x freq
  24. # 1 4    1
  25. # 2 5    1
  26. # 3 6    4
Advertisement
Add Comment
Please, Sign In to add comment