diff(x, lag=1, differences=1)
Any operation on an NA produces an NA. For matrices, the differences are performed on each column separately.
# second difference of lag 4: # the start date of d2x will be # 8 periods later than x freeny.rts<- as.rts(freeny.y) freeny.df2 <- diff(freeny.rts, 1,2)# 10th difference of an alternating series diff(rep(c(-1,1),10), 1, 10) [1] -1024 1024 -1024 1024 -1024 1024 -1024 1024 [9] -1024 1024
diff(range(x)) # max(x) - min(x)