R包'timetk'中函数'diff_vec'中的参数'difference'如何理解?
In R package 'timetk', how to understand the parameter 'difference' in function 'diff_vec'?
在R包'timetk'中,如何理解函数'diff_vec'中的参数'difference'?
library(timetk)
1:10 %>% diff_vec(lag=1)
#result: [1] NA 1 1 1 1 1 1 1 1 1
我尝试更改 'difference' 的值,但无法理解结果
#what's the usage of parameter 'difference'
1:10 %>% diff_vec(lag=1,difference = 1)
#result: [1] NA 1 1 1 1 1 1 1 1 1
1:10 %>% diff_vec(lag=1,difference = 2)
#result: [1] NA NA 0 0 0 0 0 0 0 0
1:10 %>% diff_vec(lag=1,difference = 3)
#result: [1] NA NA NA 0 0 0 0 0 0 0
使用(1:10)^2
可能更容易理解。参数difference
是对连续值进行多次差分(微分)。
(1:10)^2 %>% diff_vec(lag=1,difference = 1)
[1] NA 3 5 7 9 11 13 15 17 19
对于difference = 2
表示执行difference = 1
两次。
(1:10)^2 %>% diff_vec(lag=1,difference = 1) %>% diff_vec(lag=1,difference = 1)
[1] NA NA 2 2 2 2 2 2 2 2
(1:10)^2 %>% diff_vec(lag=1,difference = 2)
[1] NA NA 2 2 2 2 2 2 2 2
同理,difference = 3
表示执行3次difference = 1
。
(1:10)^2 %>% diff_vec(lag=1,difference = 1) %>% diff_vec(lag=1,difference = 1) %>% diff_vec(lag=1,difference = 1)
[1] NA NA NA 0 0 0 0 0 0 0
(1:10)^2 %>% diff_vec(lag=1,difference = 3)
[1] NA NA NA 0 0 0 0 0 0 0
在R包'timetk'中,如何理解函数'diff_vec'中的参数'difference'?
library(timetk)
1:10 %>% diff_vec(lag=1)
#result: [1] NA 1 1 1 1 1 1 1 1 1
我尝试更改 'difference' 的值,但无法理解结果
#what's the usage of parameter 'difference'
1:10 %>% diff_vec(lag=1,difference = 1)
#result: [1] NA 1 1 1 1 1 1 1 1 1
1:10 %>% diff_vec(lag=1,difference = 2)
#result: [1] NA NA 0 0 0 0 0 0 0 0
1:10 %>% diff_vec(lag=1,difference = 3)
#result: [1] NA NA NA 0 0 0 0 0 0 0
使用(1:10)^2
可能更容易理解。参数difference
是对连续值进行多次差分(微分)。
(1:10)^2 %>% diff_vec(lag=1,difference = 1)
[1] NA 3 5 7 9 11 13 15 17 19
对于difference = 2
表示执行difference = 1
两次。
(1:10)^2 %>% diff_vec(lag=1,difference = 1) %>% diff_vec(lag=1,difference = 1)
[1] NA NA 2 2 2 2 2 2 2 2
(1:10)^2 %>% diff_vec(lag=1,difference = 2)
[1] NA NA 2 2 2 2 2 2 2 2
同理,difference = 3
表示执行3次difference = 1
。
(1:10)^2 %>% diff_vec(lag=1,difference = 1) %>% diff_vec(lag=1,difference = 1) %>% diff_vec(lag=1,difference = 1)
[1] NA NA NA 0 0 0 0 0 0 0
(1:10)^2 %>% diff_vec(lag=1,difference = 3)
[1] NA NA NA 0 0 0 0 0 0 0