程序代写代做代考 Assignment 1

Assignment 1
YOUR NAME
September 27, 2020 (due October 4, 2019)
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
x = seq(from = -2,to = 3,by = .1)
length(x) # 51 elements
## [1] 51
s = 6
head(x,s)
## [1] -2.0 -1.9 -1.8 -1.7 -1.6 -1.5
tail(x,s)
## [1] 2.5 2.6 2.7 2.8 2.9 3.0
median(x)
## [1] 0.5
x
## [1] -2.0 -1.9 -1.8 -1.7 -1.6 -1.5 -1.4 -1.3 -1.2 -1.1 -1.0 -0.9 -0.8 -0.7
## [15] -0.6 -0.5 -0.4 -0.3 -0.2 -0.1 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7
## [29] 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1
## [43] 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0
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\). 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