Tutorials › Introduction to Statistics › Checking Units and Date Formats

Ethics, Data Quality and Reproducible Work · Tutorial 91 of 996

Checking Units and Date Formats

Learn how to detect mixed units and date formats, make justified conversions, and record the rules used to create consistent data.

Beginner 9 min read

What You'll Learn

  • Recognize when values in one variable use different measurement units.
  • Convert measurements with explicit formulas and consistent target units.
  • Preserve original values and choose a sensible precision for converted values.
  • Detect ambiguous date strings instead of guessing their meaning.
  • Convert interpretable dates to a consistent format and record the rules applied.

Why Units and Date Formats Need Checking

A column can contain values that look orderly but do not mean the same thing. For example, a set of temperatures might mix degrees Celsius and degrees Fahrenheit. A date column might mix year-month-day strings with day-month-year strings. If such entries are treated as though they share one representation, a calculation or sort may be misleading. A value such as 68 could mean a temperature in Fahrenheit, while the same number in Celsius describes a very different temperature.

Checking units and date formats is a data-quality task: establish what each value represents, identify inconsistent representations, and make only conversions supported by the available information. A consistent column is not necessarily a correct column, so the original values and the rules used to interpret or convert them should remain available for checking.

Definition: A unit is the agreed scale in which a quantity is expressed, such as centimeters or inches. Mixed units occur when values for the same quantity are recorded using different units. A date format is a convention for arranging the parts of a date, such as year-month-day or day-month-year. Standardizing these values means converting interpretable entries to one specified unit or format while retaining enough information to verify the conversion.

Checking and Converting Measurement Units

Start by identifying what a column measures and the unit attached to each value. Look at column names, labels, data dictionaries, collection forms, and other source information. Do not infer a unit from a number's size alone: plausible values can occur in more than one unit, and an implausible value could signal either a unit mismatch or a separate recording error.

Choose one target unit for the column and apply a stated conversion rule to every value expressed in a different unit. A conversion changes the numerical representation, not the underlying quantity. For a valid conversion, the converted value must represent the same measurement in the target unit. Keep the raw entry, the unit it used, and the converted value distinguishable; overwriting the only copy makes it harder to find or correct a mistake.

Conversion principle: If one unit equals a known number of another unit, convert by multiplying or dividing by that equivalence. For example, \(1\text{ inch}=2.54\text{ centimeters}\), so a length in inches is multiplied by \(2.54\) to express it in centimeters. For a scale with an offset, such as Fahrenheit and Celsius, use the full conversion formula rather than a simple multiplier.

Worked Example: Converting Mixed Temperature Units

Suppose a hypothetical room-temperature table contains three readings: 18°C, 68°F, and 20°C. The source notes confirm that the middle reading was recorded in Fahrenheit, while the other two were recorded in Celsius. Convert all three to degrees Celsius.

Rule. The Fahrenheit-to-Celsius relationship is \(C=(F-32)\times \frac{5}{9}\). The formula subtracts the Fahrenheit scale's offset before adjusting the size of its degree. Values already in Celsius do not need conversion.

Apply the rule. The first and third readings are already 18°C and 20°C. For the Fahrenheit reading:

$$ C=(68-32)\times\frac{5}{9} =36\times\frac{5}{9} =20^\circ\text{C}. $$

The consistent Celsius values are therefore 18°C, 20°C, and 20°C. The original entry, 68°F, should remain recorded alongside its converted value and the rule used. This makes it possible to verify that 68°F was not accidentally treated as 68°C.

The values above are exact under the stated conversion. In other data, conversions may produce many decimal places. The number of digits to retain should reflect the measurement precision and the analysis purpose; extra calculator digits do not make the original measurement more precise.

Dates: Interpret Before Standardizing

Dates require particular care because different formats can assign different meanings to the same string. The entry 04/05/2025 could mean April 5 or 4 May. Neither interpretation is justified by the string alone. Before converting it, consult the data source's documented convention or other reliable evidence. A value such as 13/05/2025 cannot be month/day/year because there is no thirteenth month, but that does not establish the meaning of every other entry in the column.

Once each date's meaning is established, an unambiguous and widely used representation is the ISO-style calendar form YYYY-MM-DD, with a four-digit year, two-digit month, and two-digit day. For example, 4 May 2025 becomes 2025-05-04. This representation helps prevent confusion between month-first and day-first formats. It does not, by itself, settle questions about time of day, time zone, or which calendar a source used; those details matter if the data include them.

Worked Example: Standardizing Mixed Date Formats

A hypothetical attendance file has three date entries: 04/05/2025, 2025-05-06, and 13/05/2025. The source documentation confirms that slash-separated dates in this file use day/month/year, and that hyphen-separated dates use year-month-day. Standardize them as YYYY-MM-DD.

First entry. Under the documented day/month/year rule, 04/05/2025 means the fourth day of the fifth month, or 4 May 2025. Its standardized form is 2025-05-04. It must not be read as April 5 merely because that is another common convention.

Second entry. The documented year-month-day rule makes 2025-05-06 the sixth day of the fifth month, or 6 May 2025. Its standardized form is already 2025-05-06.

Third entry. Under the day/month/year rule, 13/05/2025 means 13 May 2025. The standardized form is 2025-05-13.

The consistent date column is 2025-05-04, 2025-05-06, and 2025-05-13. The critical step was confirming the source conventions before interpreting the strings. The conversion should record those conventions, rather than presenting the standardized values as if their interpretation were self-evident.

Why Conversion Rules Work

A conversion rule should preserve the quantity or date represented, not merely make the entries look alike. For a simple unit conversion, the equivalence between units supplies the factor. For example, because one inch is exactly 2.54 centimeters, \(x\) inches corresponds to \(2.54x\) centimeters. The units show why the multiplication is appropriate:

$$ x\text{ inches}\times \frac{2.54\text{ centimeters}}{1\text{ inch}} =2.54x\text{ centimeters}. $$

The inch units cancel, leaving centimeters. Multiplying centimeters by the same factor would not convert them to inches; it would move in the wrong direction. For offset scales, the conversion must include both the offset and scale factor. Fahrenheit and Celsius, for instance, do not have zero points that coincide, so multiplying a Fahrenheit value by \(5/9\) alone is not a valid conversion.

Date standardization follows a related logic. It changes the written order of a known year, month, and day; it cannot determine those parts when the original string is ambiguous. In both kinds of conversion, the evidence and rule must be established before changing the representation.

Record the Rules and Keep the Evidence

For each affected variable, record the target unit or date format, the conversion rule, and how the original entries were identified. For example, a rule might state: “Temperatures recorded in Fahrenheit were converted to Celsius using \(C=(F-32)\times 5/9\); entries already in Celsius were retained.” A date rule might state: “Slash-separated dates follow the source's documented day/month/year convention and were reformatted as YYYY-MM-DD.” Include the source of the convention when it is available.

Retain the raw values, or otherwise preserve an unchanged source copy, so that a reviewer can compare each original entry with its standardized value. If the unit or date convention cannot be established, flag the entry for clarification rather than silently assigning an interpretation. A blank or flagged value is more honest than a confident-looking conversion based on a guess.

1
Identify the quantity or date meaning.
Check the variable definition and source information to establish what each entry represents and which unit or date convention applies.
2
Choose one target representation.
Specify a unit for the whole measurement column or a date format for the whole date column.
3
Convert only supported entries.
Apply the stated rule consistently. Set aside unclear entries rather than guessing.
4
Check and record.
Compare converted values with their originals, retain the original information, and record the rule and source convention.

Common Mistakes

  • Assuming a number's unit from its size. A value that seems typical in one unit may still have been recorded in another. Check labels or source documentation before converting.
  • Applying a simple multiplier to an offset scale. Multiplying a Fahrenheit reading by \(5/9\) omits the offset. Use the complete formula \(C=(F-32)\times 5/9\).
  • Guessing what an ambiguous date means. Reading 04/05/2025 as either April 5 or 4 May without evidence is not standardization. Confirm the source convention or leave the meaning unresolved.
  • Replacing the raw data with converted values. Keeping only the cleaned entries removes evidence needed to audit or revise the conversion. Preserve the original value and the rule.
  • Rounding more than the data justify. A long decimal result does not imply precise measurement. Choose and record a sensible rounding policy that does not suggest unsupported accuracy.
Key takeaway: Standardize units and dates only after establishing what the original values mean. Use an explicit conversion rule, check that it preserves the intended quantity or date, retain the original information, and record the convention used.

Check Your Understanding

Try these questions without looking back.

  1. A hypothetical length column contains 2 meters and 250 centimeters. If meters are the target unit, what conversion rule applies, and what is the second value in meters?
  2. A temperature column contains 50°F and 10°C. Convert the Fahrenheit value to Celsius using the stated formula.
  3. A file contains 07/08/2025, but no source convention is available. Why is converting it directly to YYYY-MM-DD unjustified?
  4. A source confirms that its slash-separated dates use day/month/year. What does 07/08/2025 mean, and how is it written as YYYY-MM-DD?
  5. Name two pieces of information that should be retained or recorded when standardizing a mixed-unit column.