Table.offset
offsetcolumnsnfill_withgroup_byorder_byset_modeon_problemserror_on_missing_columns
Group: Values
Aliases: displace, lag, lead, shift, slide
Documentation
Returns a table with new columns offset by n rows, where missing values have been replaced with the provided fill_with strategy.
Arguments
columns: The columns to offsetn: The number of rows to offset the new columns by. Negative n slides the values down in the columns' order adding records at the start. Positive n slides the values up in the columns' order adding records at the end. Defaults to -1.fill_with: The value to replace missing values with. Defaults to adding Nothing Values.-: ..Nothing - Add Nothing values in the spaces created by sliding the existing values.-: ..Closest_Value - If n is negative the first value gets used, if n is negative the last value gets used.-: ..Wrap_Around - In this mode values that slide off the top or bottom reappear at the other end. So no values get lost they are just rotated.group_by: Applies the offset to each group as a separate batch of records.order_by: The order to slide the records through. The actual record order remains the same but the records move as per the order defined by these columns.set_mode: By default creates new columns, but choosing Update replaces the existing fields being offset.on_problems: Missing columns are always an error. Other warnings like grouping on floating point numbers can be ignored or made an error with this argument.error_on_missing_columns: IfTrue, an error is raised if any of the specified columns are not found in the table. IfFalse, missing columns are ignored.
Returns
- A Table of all records, with the selected columns offset by the number specified by n.
Errors
- If the columns specified in
group_byororder_byare not present in the table, aMissing_Input_Columnserror is raised. - If grouping on floating point numbers, a
Floating_Point_Equalityproblem is reported.
Remarks
Ordering of rows
Note that the ordering of rows from the original table is preserved in all cases. The grouping and ordering settings affect how the values move as they are offset, but the order of the rows itself is not changed by this operation.