Calculation - Last

From Q
(Redirected from Calculate - Last)
Jump to navigation Jump to search



Extracts the last rows or columns (e.g. last 2 rows or last 5 columns) of selected summary tables, crosstabs or R vectors, R matrices, R arrays, R data frames, R lists or R tables, and saves them as a new R outputs. Alternatively, if the input data is labeled with dates or date-times, this feature is able to extract the last date or time periods in the data, e.g., last 3 years, last week, last 10 hours etc. A new R output is created for each selected output and this R output contains controls which allow settings to be specified (see Options section below).

Examples

Shown below is the output from extracting the last 3 rows from a summary table of a Pick One questionNominal variable set for Age:

Last rows.PNG

Shown below is the output from extracting the last 1 calendar month from an R vector that is labeled with dates ending with November 10, 2020. If instead a non-calendar period was specified (see Calendar periods in the Options section below), all dates down to and including October 11, 2020 would be extracted.

Last month.PNG

Options

Data The data output from which rows or columns are to be extracted. This can be a summary table, crosstab or R vector, R matrix, R array, R data frame, R list or R table.

Unit Specify whether to extract last rows, columns, or date-time periods (year, quarter, month, week, day, hour, minute, second) from the data. If the data is one-dimensional, "Row" should be selected for this option.

Keep The number of units (specified in the previous control) to extract.

Calendar periods Whether to consider calendar periods. When calendar periods are considered, a year is counted as the 12-month period from January to December; a quarter is one of the following 3-month periods: January-March, April-June, July-September, October-December; a month is the period from the first to last day in the 12 months in the calendar; a week is the 7 day period from Sunday to Saturday; a day is the 24 hour period from midnight to midnight; and hours, minutes and seconds are the fixed periods as indicated on a clock. For example, if the last 2 calendar years are to be kept and the latest date in the data is Nov 6, 2020, all data labeled in 2019 and 2020 will be kept. When non-calendar periods are considered instead, all periods are compared against a reference date-time, which is the latest date-time in the labels. For periods that do not have a fixed duration, i.e., years, quarters and months, a period is defined using the day and month of the reference date-time. For example if the reference date-time is Nov 6 2020 12:34:56pm, and the last 2 years of data are to be kept, all data down to (but not including) Nov 6 2018 12:34:56pm would be retained. If the reference date-time falls on a day for which the corresponding end-of-period date-time does not exist, then all actual date-times up to this mock end-of-period date-time are considered. For example, 1 year before Feb 29 2020 12:34:56pm includes all date-times down to and including March 1 2019.

Code

includeWeb('Table Selection Functions');
selectFromTables('Last rows');

See Also