There are many ways to hide rows or columns based on the sample size depending on the type of table you are using. Typically, you'd use a Table Rule, such as Hide Rows and Columns with Small Sample Sizes (see this article), but if you are using R to create your table or need more custom logic, you can do this using R code as described in this article. For example, you can go from a table showing all the data:
To a table that only shows data for rows/columns with sufficient data (I'm using a Sample Size threshold of 20 for the table below):
Requirements
- A table showing at least two statistics in the Statistics > Cells dropdown, one of which being either Row Sample Size or Column Sample Size
- General knowledge of How to Work with Data in R and How to Work with Conditional R Formulas.
Method - Hide rows
In this example, we'll hide all rows with a Row Sample Size of less than 20 in the first column. If you have different bases for the different columns, you can specify a different column to use.
- Click Calculation
> Custom Code from the toolbar, and click on the page to place the custom object.
-
Paste the code below into the R Code editor. Change
table.Preferred.cola.by.Quarterly.dates.6 to the name of your table, and edit the threshold of 20 and final statistic to show (currently Column %) as needed.#identify table
x=table.Preferred.cola.by.Quarterly.dates.6
#identify rows with sample sizes above 20 in the first column
#change 20 if needed
keeprows=x[,1,"Row Sample Size"] > 20
#return table without those rows
#return the Column % or change that to the other stat in your table
x[keeprows,,"Column %"] - Click Calculate.
- OPTIONAL: Add % signs and reduce the number of decimals shown from the Appearance > Appearance options in the object inspector.
Method - Hide Columns
Similar to above, if you'd like to remove columns based on Column Sample Size of 20 you can use the code below:
#identify table
x=table.Preferred.cola.by.Quarterly.dates.6
#identify cols with sample sizes above 20 in the first row
#change 20 if needed
keepcols=x[1,,"Column Sample Size"] > 20
#return table without those cols
#return the Column % or change that to the other stat in your table
x[,keepcols,"Column %"]
Next
How to Hide Rows and Columns with Small Sample Sizes in Tables and Visualizations
How to Blank or Cap R Table Cells Based on a Different Statistic Using R
How to Hide an Output with a Small Sample Size Using an R Error
How to Hide an Output with a Small Sample Size Using a Calculation