I disagree that this type of question should be directed elsewhere. R is tightly bound to statistics and learning it involves understanding both.
For this question, see the explainer for the first part. Come back with a new question with the time domain question. Post a reprex. See the FAQ.