x <- sample(x=1:100, size=100, replace=TRUE)
head(x)
## [1] 17 37 77 38 61 25
length(x)
## [1] 100
mean(x)
## [1] 50.71
x[1:25]
## [1] 17 37 77 38 61 25 4 82 91 60 12 19 19 69 24 40 79 26 2 27 84 29 24 41 43
knitr::opts_chunk$set(echo = TRUE)
x <- sample(x=1:100, size=100, replace=TRUE)
head(x)
## [1] 9 5 96 55 96 27
length(x)
## [1] 100
mean(x)
## [1] 45.89
x[1:25]
## [1] 9 5 96 55 96 27 29 94 91 17 15 7 71 13 63 16 27 37 21 80 17 10 31 44 24
grades <- c(95, 72, 87, 66)
weights <- c(1/2, 1/4, 1/8, 1/8)
mean(grades)
## [1] 80
sum(weights)
## [1] 1
weighted.mean(x=grades, w=weights)
## [1] 84.625
sum(grades*weights)/4*4
## [1] 84.625
x <- sample(x=1:100, size=100, replace=TRUE)
head(x)
## [1] 65 92 56 89 85 89
length(x)
## [1] 100
mean(x)
## [1] 52.27
x[1:25]
## [1] 65 92 56 89 85 89 49 57 68 25 37 51 4 24 43 6 58 78 60 86 87 86 41 86 35
y <- x
yy <- sample(x=1:100, size=20, replace=FALSE)
y[yy] <- NA # Set 20 random elements in y to NA