x1 <- seq(0, 10, length = 5)
x1
## [1] 0.0 2.5 5.0 7.5 10.0
x2 <- seq(0, 10, length = 6)
x2
## [1] 0 2 4 6 8 10
x3 <- seq(0, 10, length = 7)
x3
## [1] 0.000000 1.666667 3.333333 5.000000 6.666667 8.333333 10.000000
x4 <- seq(0, 77, length = 100)
x4
## [1] 0.0000000 0.7777778 1.5555556 2.3333333 3.1111111 3.8888889
## [7] 4.6666667 5.4444444 6.2222222 7.0000000 7.7777778 8.5555556
## [13] 9.3333333 10.1111111 10.8888889 11.6666667 12.4444444 13.2222222
## [19] 14.0000000 14.7777778 15.5555556 16.3333333 17.1111111 17.8888889
## [25] 18.6666667 19.4444444 20.2222222 21.0000000 21.7777778 22.5555556
## [31] 23.3333333 24.1111111 24.8888889 25.6666667 26.4444444 27.2222222
## [37] 28.0000000 28.7777778 29.5555556 30.3333333 31.1111111 31.8888889
## [43] 32.6666667 33.4444444 34.2222222 35.0000000 35.7777778 36.5555556
## [49] 37.3333333 38.1111111 38.8888889 39.6666667 40.4444444 41.2222222
## [55] 42.0000000 42.7777778 43.5555556 44.3333333 45.1111111 45.8888889
## [61] 46.6666667 47.4444444 48.2222222 49.0000000 49.7777778 50.5555556
## [67] 51.3333333 52.1111111 52.8888889 53.6666667 54.4444444 55.2222222
## [73] 56.0000000 56.7777778 57.5555556 58.3333333 59.1111111 59.8888889
## [79] 60.6666667 61.4444444 62.2222222 63.0000000 63.7777778 64.5555556
## [85] 65.3333333 66.1111111 66.8888889 67.6666667 68.4444444 69.2222222
## [91] 70.0000000 70.7777778 71.5555556 72.3333333 73.1111111 73.8888889
## [97] 74.6666667 75.4444444 76.2222222 77.0000000
round(x4)
## [1] 0 1 2 2 3 4 5 5 6 7 8 9 9 10 11 12 12 13 14 15 16 16 17 18 19
## [26] 19 20 21 22 23 23 24 25 26 26 27 28 29 30 30 31 32 33 33 34 35 36 37 37 38
## [51] 39 40 40 41 42 43 44 44 45 46 47 47 48 49 50 51 51 52 53 54 54 55 56 57 58
## [76] 58 59 60 61 61 62 63 64 65 65 66 67 68 68 69 70 71 72 72 73 74 75 75 76 77
floor(x4)
## [1] 0 0 1 2 3 3 4 5 6 7 7 8 9 10 10 11 12 13 14 14 15 16 17 17 18
## [26] 19 20 21 21 22 23 24 24 25 26 27 28 28 29 30 31 31 32 33 34 35 35 36 37 38
## [51] 38 39 40 41 42 42 43 44 45 45 46 47 48 49 49 50 51 52 52 53 54 55 56 56 57
## [76] 58 59 59 60 61 62 63 63 64 65 66 66 67 68 69 70 70 71 72 73 73 74 75 76 77
ceiling(x4)
## [1] 0 1 2 3 4 4 5 6 7 7 8 9 10 11 11 12 13 14 14 15 16 17 18 18 19
## [26] 20 21 21 22 23 24 25 25 26 27 28 28 29 30 31 32 32 33 34 35 35 36 37 38 39
## [51] 39 40 41 42 42 43 44 45 46 46 47 48 49 49 50 51 52 53 53 54 55 56 56 57 58
## [76] 59 60 60 61 62 63 63 64 65 66 67 67 68 69 70 70 71 72 73 74 74 75 76 77 77
rep(c("A","B","C"),3)
## [1] "A" "B" "C" "A" "B" "C" "A" "B" "C"
rep(c("A","B","C"),each = 3)
## [1] "A" "A" "A" "B" "B" "B" "C" "C" "C"
rep(c("A","B","C"),each = 2, 3)
## [1] "A" "A" "B" "B" "C" "C" "A" "A" "B" "B" "C" "C" "A" "A" "B" "B" "C" "C"
rep(1:9,2)
## [1] 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9
rep(1:9, each = 2,3)
## [1] 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 1 1
## [39] 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9
mix(), max, var, range
set.seed(555)
sample(0:1, 10, replace = TRUE)
## [1] 1 0 1 1 0 0 0 1 0 1
sample(c("A", "G"), 8, replace = TRUE)
## [1] "G" "G" "G" "A" "G" "G" "G" "A"
sample(1:6, 10,, replace = T)
## [1] 5 5 1 1 1 3 4 2 6 2
set.seed(123)
n <- 100
uniform_data <- runif(n, min = 0, max = 1)
hist(uniform_data, xlab = "nilai",breaks = 20, main = "Histogram Distribusi Uniform", col = "yellow")
n_trials <- 10
p_success <- 0.5
binomial_data <- rbinom(n, size = n_trials, prob = p_success)
hist(binomial_data, breaks = 15, main = "Histogram Distribusi Binomial", xlab = "Jumlah Sukses", col = "maroon")
### SIMULASI DIST DISKRIT : POISSON
lambda = 15
poisson_data <- rpois(n, lambda)
hist(poisson_data, breaks = 10, main = "Histogram Distribusi Poisson", xlab = "Jumlah kejadian", col = "grey" )
### SIMULASI DIST DISKRIT : EKSPONENSIAL
rate <- 1
exp_data <- rexp(n, rate)
hist(exp_data, breaks = 25, main = "Histogram Distribusi Eksponensial", xlab = "Nilai", col = "coral" )
### SIMULASI DIST KONTINu : DIst NORMAL
mu <- 0
sigma <- 1
normal_data <- rnorm(n, mu, sigma)
normal_data
## [1] -0.75268897 -0.93853870 -1.05251328 -0.43715953 0.33117917 -2.01421050
## [7] 0.21198043 1.23667505 2.03757402 1.30117599 0.75677476 -1.72673040
## [13] -0.60150671 -0.35204646 0.70352390 -0.10567133 -1.25864863 1.68443571
## [19] 0.91139129 0.23743027 1.21810861 -1.33877429 0.66082030 -0.52291238
## [25] 0.68374552 -0.06082195 0.63296071 1.33551762 0.00729009 1.01755864
## [31] -1.18843404 -0.72160444 1.51921771 0.37738797 -2.05222282 -1.36403745
## [37] -0.20078102 0.86577940 -0.10188326 0.62418747 0.95900538 1.67105483
## [43] 0.05601673 -0.05198191 -1.75323736 0.09932759 -0.57185006 -0.97400958
## [49] -0.17990623 1.01494317 -1.99274849 -0.42727929 0.11663728 -0.89320757
## [55] 0.33390294 0.41142992 -0.03303616 -2.46589819 2.57145815 -0.20529926
## [61] 0.65119328 0.27376649 1.02467323 0.81765945 -0.20979317 0.37816777
## [67] -0.94540883 0.85692301 -0.46103834 2.41677335 -1.65104890 -0.46398724
## [73] 0.82537986 0.51013255 -0.58948104 -0.99678074 0.14447570 -0.01430741
## [79] -1.79028124 0.03455107 0.19023032 0.17472640 -1.05501704 0.47613328
## [85] 1.37857014 0.45623640 -1.13558847 -0.43564547 0.34610362 -0.64704563
## [91] -2.15764634 0.88425082 -0.82947761 -0.57356027 1.50390061 -0.77414493
## [97] 0.84573154 -1.26068288 -0.35454240 -0.07355602
hist(normal_data, breaks = 20, main = "Histogram Distribusi Normal", xlab = "Nilai", col = "pink")