simple examples of filter function, recursive option specifically

前端 未结 4 1757
走了就别回头了
走了就别回头了 2020-12-02 15:36

I am seeking some simple (i.e. - no maths notation, long-form reproducible code) examples for the filter function in R I think I have my head around the convolu

4条回答
  •  情书的邮戳
    2020-12-02 16:17

    Here's the example that I've found most helpful in visualizing what recursive filtering is really doing:

    (x <- rep(1, 10))
    # [1] 1 1 1 1 1 1 1 1 1 1
    
    as.vector(filter(x, c(1), method="recursive"))  ## Equivalent to cumsum()
    #  [1]  1  2  3  4  5  6  7  8  9 10
    as.vector(filter(x, c(0,1), method="recursive"))
    #  [1] 1 1 2 2 3 3 4 4 5 5
    as.vector(filter(x, c(0,0,1), method="recursive"))
    #  [1] 1 1 1 2 2 2 3 3 3 4
    as.vector(filter(x, c(0,0,0,1), method="recursive"))
    #  [1] 1 1 1 1 2 2 2 2 3 3
    as.vector(filter(x, c(0,0,0,0,1), method="recursive"))
    #  [1] 1 1 1 1 1 2 2 2 2 2
    

提交回复
热议问题