R语言中diff函数,表示滞后差分

 

1、测试1

test <- sample(1:10,5)
test
a <- diff(test)    ## diff表示后一个数减去前一个数
a

R语言中diff函数

 

 2、测试2

test <- sample(1:10,5)
test
a <- diff(test)
a
b <- diff(test,differences = 2)   ## differences 参数表示连续执行两次diff
b

R语言中diff函数

 

 

 3、测试3

test <- sample(1:10,5)
test
c <- diff(test, lag = 2)   ## lag表示中间有两个间距的数只差,比如第三数和第一个数只差,以此类推
c

R语言中diff函数

 

4、测试4  矩阵测试

a <- matrix(c(3,4,2,5,8,2,8,1,7,5,2,5),4,3)
a
diff(a[,1])
diff(a)

R语言中diff函数

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-28
  • 2022-12-23
猜你喜欢
  • 2021-11-18
  • 2021-07-04
  • 2021-08-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案