Subset a worksheet: keep or delete rows by a condition
Subsetting a worksheet keeps only the rows you want, or deletes the ones you do not, across every column at once. You pick the rows with a condition, such as Shift = "Night", or with a list of row numbers. It is how you narrow a large data set to one machine, one shift or one lot before you analyze it, or remove rows that should not be there, such as test shots.
When to use it
- You want to analyze one group on its own: one press, one supplier, one product.
- You need to drop rows that do not belong in a study: setup parts, rejected test runs, readings taken after a known change.
- You want to remove rows with missing values in a key column before exporting the data.
- You want to keep a time window, such as the rows of one week, using a condition on a date column.
If you only want to compare groups, you often do not need a subset at all: most analyses can take a group column. Subsetting is for when the other rows should leave the worksheet.
How to do it in StatLab
- Choose Data › Subset worksheet….
- Under Choose rows by, pick one:
- A condition: a formula that is true for the rows you mean, written as in Calc › Calculator. Examples:
'Weight' > 251,Press = "P1",Shift = "Night" AND NOT ISMISSING(Weight). - Row numbers: a list such as
1:10, 15, 20:25.
- A condition: a formula that is true for the rows you mean, written as in Calc › Calculator. Examples:
- Under What to do, pick Keep these rows, delete the rest or Delete these rows.
- Read the line under the fields. It says how many rows will remain, for example Keeps 4 of 10 rows, or what is wrong with the condition.
- Press OK. Results records how many rows were kept. Ctrl+Z undoes the subset.
Rules that matter:
- Whole rows. Rows are kept or deleted in every column, so each part's values stay together.
- Text comparisons are exact.
Press = "p1"does not matchP1. Write text in double quotes, exactly as it appears in the worksheet. - Combine conditions with
AND,ORandNOT, and group them with parentheses. - Missing values never match. If a row's condition cannot be worked out because a value it needs is missing, the row counts as not matching. With Keep these rows it is deleted; with Delete these rows it stays.
Example
A molding area runs two presses on two shifts. Supervisors suspect night-shift parts are heavier. The worksheet holds ten parts; one weight was not recorded.
Before:
| C1-T Shift | C2-T Press | C3 Weight (g) |
|---|---|---|
| Day | P1 | 250.4 |
| Day | P2 | 249.7 |
| Night | P1 | 251.2 |
| Night | P2 | * |
| Day | P1 | 250.9 |
| Night | P1 | 252.2 |
| Night | P2 | 249.9 |
| Day | P2 | 250.1 |
| Night | P1 | 251.6 |
| Day | P1 | 250.3 |
To study the night shift's measured parts, the engineer saves the project, then chooses Data › Subset worksheet…, A condition, and types:
Shift = "Night" AND NOT ISMISSING(Weight)
The dialog shows Keeps 4 of 10 rows. Five rows are from the night shift, and one of them has no weight. With Keep these rows, delete the rest, she presses OK. Results: Kept 4 of 10 rows.
After:
| C1-T Shift | C2-T Press | C3 Weight (g) |
|---|---|---|
| Night | P1 | 251.2 |
| Night | P1 | 252.2 |
| Night | P2 | 249.9 |
| Night | P1 | 251.6 |
The remaining rows suggest the heavy night parts all come from press P1, which narrows the question. She undoes the subset and tries Press = "P1" instead, which keeps the six P1 rows from both shifts.
Two variations on the same data:
- Delete these rows with
'Weight' > 251deletes rows 3, 6 and 9 and keeps the other seven, including row 4, because its missing weight cannot be compared with 251. - Row numbers
4, 7with Delete these rows removes exactly those two rows and keeps eight.
How to read the results
- Check the count before you press OK. If you expected about half the rows and the dialog says Keeps 0 of 10 rows, the condition is wrong, often a spelling or capitalization difference in a text value.
- Read the message when the condition fails. The dialog says what is wrong, such as a column name it does not know, or that the condition must be true or false for each row.
- Read Results afterwards. It keeps a record of how many rows the subset left, which you can cite in a report.
Common mistakes
- Subsetting without a copy. Subset changes this worksheet. Save the project first, or use Save project as… for the subset, so the full data stays available. Undo also works.
- Wrong capitalization.
Line = "a"does not matchA. Copy the value from a cell if you are not sure how it is written. - Forgetting the missing values.
Weight < 250keeps no rows with a missing weight, and with Delete these rows it leaves them all in. AddISMISSING(Weight)to the condition when you want to treat them explicitly. - Cherry-picking. Deleting rows only because they look bad is not data cleaning. Remove rows for a documented reason, such as setup parts or a known instrument fault, and say so in your report.
Frequently asked questions
How do I keep rows between two dates?
Compare the date column with two dates made with DATE(year, month, day), for example Measured >= DATE(2026, 11, 1) AND Measured < DATE(2026, 12, 1) for November.
How do I delete every row with a missing value in one column?
Use A condition with ISMISSING(Weight) and choose Delete these rows.
Can I subset by row numbers and a condition together?
Not in one step. Run the subset twice, once with each, or combine them in the condition using a column of row numbers made with Calc › Make patterned data….
Does subset change other columns?
Yes, on purpose. Rows are kept or deleted across every column, so the worksheet stays consistent.