x <- 1:25Classwork 3
Descriptive Statistics and Vector Selection
Question 1.
- Write an R code to calculate the standard deviation (SD) of the integer vector
xbelow manually. That is to calculate the SD without using thesd()or thevar()functions.
- Also, write an R code to test whether the standard deviation you calculate manually above is equal to
sd(x).
Answer:
Question 2.
- Write an R code to calculate the range (difference between the maximum and minimum values) of the vector
temp <- c(22, 28, 31, 25, 29).
temp <- c(22, 28, 31, 25, 29)Answer:
Question 3.
- Consider the vector
scores <- c(12, 7, 15, 10, 20, 18, 5, 14). Write an R code to calculate the first quartile (Q1), median (Q2), and third quartile (Q3) using thequantile()function. Also, calculate the interquartile range (IQR).
scores <- c(12, 7, 15, 10, 20, 18, 5, 14)Answer:
Question 4.
- Consider the vectors:
my_vec <- c(-10, -20, 30, 10, 50, 40, -100)
beers <- c("BUD LIGHT", "BUSCH LIGHT", "COORS LIGHT",
"GENESEE LIGHT", "MILLER LITE", "NATURAL LIGHT")- Write an R code to filter only the positive values in
my_vec. - Write an R code to access the beers that are in positions 2, 4, and 6 using indexing.
Answer:
Question 5.
- Create a logical vector
logical_vecthat checks whether the elements of the vectorages <- c(15, 22, 18, 24, 30)are greater than or equal to 20.
ages <- c(15, 22, 18, 24, 30)Answer:
