Sometimes you may have rows and/or columns in your table or visualization that you want to match to another table, combobox, or listbox control. This article describes how you can match rows, columns, and the order of rows and columns using rules. Secondarily, you can achieve the same results using a widget —an R-based feature —but this option is less efficient than using rules.
This article describes how to transform a default table output:
To a table that shows only selected rows and columns and matches the order of the table referenced:
Requirements
A Displayr document with a data set.
Method 1 - Using table Rules
Rules are predefined automated functions that allow some conditions to be specified. Rules can be applied to outputs you have selected (Page(s) or Folder(s) in the Report tree. Rules are much more efficient than using R-based widgets. Learn more about rules in How to Use Rules in Displayr.
- Select your table or visualization.
- Go to Data > Rules in the object inspector.
- Click Plus (+) > Rows/Columns > Select Matching Rows or Select Matching Coumns
- Choose a Table, Control (combobox, listbox, text box), or R item (Integer, Numeric, Character, Matrix, Array, Data Frame) from the Select rows using the dropdown menu.
- Select rows or columns from the Use selected input's dropdown menu.
- Select the order of the rows or columns based on the selected input or the original order.
- [Optional] By default, the order of Rows/Columns is determined by the selected input. You can keep the original order in the table by changing the Order of rows/columns based on > original order.
- Click OK.
You can also use rules in the Rows/Columns menu to show a range of rows, show rows from the top, show specified rows, and more.
- Range - Use this rule to Show a Range of Rows to include in your table or visualization. The range can start with any row in the table by entering the first and last row to retain.
- First rows - Use this rule to Specify the Number of Rows From the Top (e.g, Top 5) of your table or visualization.
- Specify rows - Use this rule to Show a Specified Number of Rows From the Top by entering the number of rows, or Specify Rows by listing the row label to retain in a table or visualization.
- Additionally, other rules in the Rows/Columns menu will allow you to Hide Rows and Columns with Small Sample Sizes, Hide Empty Rows and Columns, Hide NETs, Hide Non-Significant Rows and Columns, and Hide Outputs With Small Sample Sizes.
Method 2 - Using the Tables > Select widget
The Tables > Select feature is R-based and less efficient than using a rule. If you can achieve the desired results using a rule, choose that option over this R-based feature. Additionally, you will not have access to Statistics > Right and Statistics > Below from the object inspector using this feature.
- Create a new table by dragging a variable onto the page or select an existing table.
- With the table selected, go to Anything
> Table > Select.
- From the object inspector, go to Data > Table 1 and use the Select rows by dropdown to indicate how you would like to indicate what you would like to include/exclude from the table. Details of each selection are noted below.
- Repeat Step 3 for Select columns by.
Select rows/columns by dropdowns, include the following options and their respective actions:
- The default selection option is Typing labels to exclude whereby every row and column apart from NET and SUM will be selected by default. You can select and deselect the items you wish to include.
- Typing labels to include - here you will type the rows/columns that you would like to include in the Rows to include/Columns to include fields exactly as they appear in the table, each separated by a semi-colon. Displayr defaults to automatically include all rows/columns when this is selected.
- Range - Use this option to specify a numeric range of indices to include. When selected, a text box Range appears for specifying the row/column numbers to include. Ranges are specified with a hyphen and multiple ranges can be separated by a comma; eg, "2-5,8,12-15".
-
First rows/columns - If this method is chosen, a numeric field called Number of rows/columns to select appears, which specifies the number of rows/columns from the first to include; eg, specify 3 to show only the first three rows/columns of the table. Note, you can also access this option directly from the toolbar via Calculation
> First.
-
Last rows/columns - Similar to First rows/columns, except for selecting rows/columns from the bottom of the table. Note, you can also access this option directly from the toolbar via Calculation
> Last.
-
Control or output from Page(s) - If this method is chosen, a drop-down called Control to select row(s)/column(s) appears, which can be used to supply a Calculation (via Calculation
> Custom Code) or Control box (via Anything
> Page Design > Control) containing the row/column labels to include.
There are also date/time specific settings for when date/time variables are present in the rows/columns of the table. See How to Select Specific Rows and Columns to Appear in a Date/Time Table for an example. These settings include:
-
First date-time periods - This method can be used when the row/columns labels of the table contain dates to select. Three additional controls appear in this case:
- Date-time period specifies the date-time unit/period to consider, e.g. "Year", "Month", "Quarter", etc.
- First date-time periods to select specifies the number of periods from the first date in the table to include
- Calendar - If this is checked then the date-time periods selected will be relative to the calendar, e.g., the first quarter is always January - March. If unchecked, then date-time periods are counted relative to the first date in the table.
- Last date-time periods - Similar to "First date-time periods", except for selecting dates in relation to the last date in the table.
- Date range - If this option is selected, two controls appear Start date and End date, and only rows with dates falling between the chosen start and end dates will appear in the output table.
OPTIONAL: Update Appearance > Appearance > Decimals and Number format as required.
How to Switch Between Tables via a Control Box when selecting more than one table.
Next
Select Which Rows or Columns to Show in a Visualization Based on a Control Box Selection
How to Hide Rows and Columns with Small Sample Sizes in Tables and Visualizations
How to Hide Empty Rows and Columns in a Table or Visualization
How to Automatically Hide NETs from Tables
How to Hide Non-Significant Rows and Columns
How to Hide Outputs With Small Sample Sizes
How to Show Only a Specified Number of Rows From the Top of a Table or Visualization
How to Show a Range of Rows in a Table or Visualization
How to Select Specific Rows and Columns to Appear in a Date/Time Table