Check-in 4

Author

YOUR NAME HERE

Remember, follow the instructions below and use R Markdown to create a pdf document with your code and answers to the following questions on Gradescope. You may find a template file by clicking “Code” in the top right corner of this page.

  1. The hard-threshold function is defined as

\[f_\lambda(x) =\begin{cases} x & |x|\geq \lambda\\ 0 & |x|<\lambda \end{cases}\]

Write an R function that takes two arguments as input: a numeric input x and a threshold lambda. Your function should return the value of \(f_\lambda(x)\) and work for vector input x of any length.

  1. For \(\lambda=4\), demonstrate your function on the vector c(-5, -3, 0, 3, 5).

(Hint: the output should be the vector -5, 0, 0, 0, 5)

  1. For \(\lambda=2\), demonstrate your function on the vector c(-7, -5, -3, 0, 3, 5, 7).