程序代写代做代考 {r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE)

{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE)

Note: This is an individual assignment. No discussion with a fellow student is allowed. Honor code is in place.

Question 1

Create a numeric vector (call it x) that starts from -2 to 3 by .1 (the increment). Now answer the following questions.

1. How many elements does x have?
2. Now let s = 6. How would you extract the first s elements of x? How would you extract the last s elements of x?
3. How would you extract all the elements of x that are within .6 of the median of x?

# write your code here

Question 2

1. Create a sequence of class Date that starts from September 1, 2020 and ends on September 30, has all the days, but omits weekend days.

# write your code here

Question 3

1. Write a function (call it mylm) that takes two inputs: a vector y of n elements and a matrix X of n times k elements, where n should be greater than k, and returns two outputs: X′X and X′y (the prime symbol means transpose). Use the attr method to return the second output.

# write your code here

Question 4

1. Now write the same function as in Q3, but use the list method to return the second output.

# write your code here