Details

The function first determines the trend component using a moving
average (if filter is NULL, a symmetric window with
equal weights is used), and removes it from the time series. Then,
the seasonal figure is computed by averaging, for each time unit, over
all periods. The seasonal figure is then centered. Finally, the error
component is determined by removing trend and seasonal figure
(recycled as needed) from the original time series.

This only works well if x covers an integer number of complete
periods.