n <- 24*7*2            
t <- 1:n               
n.tr <- floor(n * 0.8) 
n.te <- n - n.tr       
ii.tr <- 1:n.tr        
ii.te <- (n.tr+1):n 

set.seed(5)

y <- 100 + 0.1 * t + 0.02 * t^2 + 100 * sin(2 * pi * t / 24) + rnorm(n, sd = 5)

matplot(y, type = 'o', pch = 1, col = 2)

q <- 24

d <- 1

dy <- diff(y[ii.tr], diff = d)

matplot(dy, type = 'o', pch = 1, col = 2, ylab = 'y')

library(forecast)
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo