Q1. Create a numeric vector called x with 1000 numbers. You can use any function or operator of your choice.

x = runif(1000)


Q2. Use length() to verify that x has exactly 1000 elements.

length(x)
## [1] 1000


Q3. Compute the mean, minimum, maximum and range of x.

mean(x)
## [1] 0.5012098
min(x)
## [1] 0.000440466
max(x)
## [1] 0.999839
range(x)
## [1] 0.000440466 0.999838982


Q4. Write an expression that returns the 5th element of x.

x[5]
## [1] 0.8802926


Q5. Write an expression that returns the 6th through 10th elements of x.

x[6:10]
## [1] 0.8733721 0.5301184 0.9430610 0.9559014 0.7440458


Q6. Create a character vector containing the names of your top-three favorite flavors of ice cream.

my_favorites = c("vanilla", "chocolate chip", "mocha")

my_favorites
## [1] "vanilla"        "chocolate chip" "mocha"


Q7. Write an expression that returns a vector containing the FIRST 10 UPPERCASE letters of the alphabet.

LETTERS[1:10]
##  [1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J"


Q8. Write an expression that returns a vector containing the LAST 5 LOWERCASE letter of the alphabet.

letters[21:26]
## [1] "u" "v" "w" "x" "y" "z"


Q9. Write an expression that returns a vector containing the EVEN numbers from 1 to 20 (i.e., 2, 4, 6, 8, …, 20).

1:10 * 2
##  [1]  2  4  6  8 10 12 14 16 18 20


Q10. Write an expression that returns a vector containing the ODD numbers from 1 to 20 (i.e., 1, 3, 5, 7, …, 19).

(1:10 * 2) - 1
##  [1]  1  3  5  7  9 11 13 15 17 19


Q11. Generate 100 random numbers using rnorm(), saving the results to an object called my_nums.

my_nums = rnorm(100)


Q12 Write an expression that returns the elements of my_nums that are greater than 1.

my_nums[ my_nums > 1 ]
##  [1] 1.735812 1.884419 1.220173 1.080568 1.250175 1.075364 2.244210 1.459166
##  [9] 1.356417 2.248809 1.219744 1.375777 1.765311 1.229856 2.069471 1.547659
## [17] 1.350288 1.013668 1.310789 1.792947 1.805619

Q13 Write an expression that tells you HOW MANY elements of my_nums are greater than 1.

sum(my_nums > 1)
## [1] 21

Q14. Write an expression that returns the current date.

Sys.Date()
## [1] "2023-09-30"