def lag k=1
      case k
      when 0 then dup
      when 1...size
        copy([nil] * k + data.to_a)
      when -size..-1
        copy(data.to_a[k.abs...size])
      else
        copy([])
      end
    end
def lag k=1
      case k
      when 0 then dup
      when 1...size
        copy([nil] * k + data.to_a)
      when -size..-1
        copy(data.to_a[k.abs...size])
      else
        copy([])
      end
    end
Lags the series by `k` periods.

 Lags the series by `k` periods, "shifting" data and inserting `nil`s
 from beginning or end of a vector, while preserving original vector's
 size.

 `k` can be positive or negative integer. If `k` is positive, `nil`s
 are inserted at the beginning of the vector, otherwise they are
 inserted at the end.

 @param [Integer] k "shift" the series by `k` periods. `k` can be
   positive or negative. (default = 1)

 @return [Daru::Vector] a new vector with "shifted" inital values
   and `nil` values inserted. The return vector is the same length
   as the orignal vector.

 @example Lag a vector with different periods `k`

   ts = Daru::Vector.new(1..5)
               # => [1, 2, 3, 4, 5]

   ts.lag      # => [nil, 1, 2, 3, 4]
   ts.lag(1)   # => [nil, 1, 2, 3, 4]
   ts.lag(2)   # => [nil, nil, 1, 2, 3]
   ts.lag(-1)  # => [2, 3, 4, 5, nil]