<- 1:25 x
Classwork 5
R Basics II
Question 1.
- Write an R code to calculate the standard deviation (SD) of the integer vector
x
below 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)
.
<- c(22, 28, 31, 25, 29) temp
Answer:
Question 3.
- Consider the vectors:
<- c(-10, -20, 30, 10, 50, 40, -100)
my_vec <- c("BUD LIGHT", "BUSCH LIGHT", "COORS LIGHT",
beers "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 4.
- Create a logical vector
logical_vec
that checks whether the elements of the vectorages <- c(15, 22, 18, 24, 30)
are greater than or equal to 20.
<- c(15, 22, 18, 24, 30) ages
Answer: