Avoiding loops in R

前端 未结 3 781
感情败类
感情败类 2021-01-16 08:48

I have decided to learn R. I am trying to get a sense of how to write \"R style\" functions and to avoid looping. Here is a sample situation:

Given a vector a<

3条回答
  •  误落风尘
    2021-01-16 09:35

    Something like b = filter(a, rep(1.0/5, 5), sides=1) will do the job, although you will probably get zeros in the first few slots, instead of NaN. R has a large library of built-in functions, and "R style" is to use those wherever possible. Take a look at the documentation for the filter function.

提交回复
热议问题