Check a column's range and missing values in R¶
Draft: not yet validated
The code on this page was run inside MESA RStudio Geospatial on 2026-11-16 (R 4.6.2), by the AI assistant that drafted it, and produced the output shown, one step at a time. No person has yet followed the steps, so a screen may differ. Tell us what you find.
You will: know the range of value at each gauge and how many missing values each
column of readings holds.
Time: 5 minutes. You need: the readings and gauges tables from
Load a file from your Data Store in RStudio, in
MESA RStudio Geospatial.
Steps¶
-
In the Console, run:
range(readings$value)You should see: the smallest value, then the largest.
[1] 0 180 -
Ask whether both ends are believable. Zero is a dry day. Decide whether 180 could be one day's rain before you read on.
You should see: a reason to look closer. A range tells you that something is unusual, not what it is.
-
Split the range by gauge:
aggregate(value ~ gauge_id, data = readings, FUN = function(v) c(min = min(v), max = max(v)))You should see:
gauge_id value.min value.max 1 G01 0.00 24.90 2 G02 0.00 2.92 3 G03 0.00 32.50 4 G04 0.00 26.40 5 G05 0.00 180.00 -
Count the missing values in every column:
colSums(is.na(readings))You should see:
gauge_id date value flag 0 0 0 150 -
Check the count against the data dictionary.
You should see: that a blank
flagis expected, since it means the sensor raised no concern, and thatvalueis never missing.
Check it worked¶
You can state two things: the largest value at each gauge, and that the only column
with missing values is flag, with 150 of them.
If it didn't¶
The counts in step 4 are all zero. flag was read as empty text, not as missing.
Read the file again with na.strings = "", as in
Load a file from your Data Store in RStudio.
Step 1 prints [1] NA NA. The column holds a missing value, and range() will not
guess around it. range(readings$value, na.rm = TRUE) leaves the missing values out;
count them first, so you know how many you set aside.
Next¶
- Tally a quality flag in R, which follows up the 180.
- "No missing values" does not mean "no missing days": a day with no row at all is not
an
NA. Count records per day in R covers that. - The same task in Python: Check a column's range and missing values.
Not yet validated by a person in MESA RStudio Geospatial. Drafted with AI assistance on 2026-11-16; the code was run there that day (R 4.6.2).
Machine-readable versions of this page: Markdown twin · raw source on GitHub · llms.txt · llms-full.txt (whole site). See For AI agents.