Rules

See the Section about Rules for Quizzes and Homeworks on the General Info page.

Your work handed into Canvas should be an Rmarkdown file with text and code chunks that can be run to produce what you did. We do not take your word for what the output is. We may run it ourselves. But we also want the output.

You may ask questions if the wording of the questions are confusing. But the instructor will not be giving hints.

Quizzes must uploaded by the end of class (1:10). It should actually allow a few minutes after that, but those not uploaded by 1:10 will be marked late. Here is the link for uploading this quiz https://canvas.umn.edu/courses/330843/assignments/2807883.

Homeworks must uploaded before midnight the day they are due. Here is the link for uploading this homework. https://canvas.umn.edu/courses/330843/assignments/2807885.

Quiz 2

Problem 1

Write an R function that, given a numeric matrix A

Not only write a function, but also show it working on the data obtained by the R command


load(url("https://www.stat.umn.edu/geyer/3701/data/2022/q2p1.rda"))
ls()

(This loads two R objects: matrices a and b. Apply your function to both.)

Note: The problem states that your function should return a matrix not a vector. Beware of the footgun behavior of square bracket function.

Problem 2

Write an R function %foo% that interleaves two character vectors of the same length (length zero is allowed). In more detail, its output vector takes the first element from the first vector (the one on the left-hand side of the operator), then the first element from the other vector, then the second element of the first vector, then the second element of the second vector, and so forth.

Test your function on some nonzero length vectors.

Problem 3

Write a function that takes a numeric matrix and symmetrizes its columns: for any vector x its symmetrization is c(x, -x).

If any components of the matrix are NA, NaN, Inf, or -Inf your function should produce an error message.

Not only write a function, but also show it working on the data obtained by the R command


load(url("https://www.stat.umn.edu/geyer/3701/data/q2p3.rda"))
ls()

(This loads one R object: a matrix a.)