signif( )
Round to a given number of significant figures. signif() is a base R function.
Required Library
# signif() is part of base R — no package installation neededUse round() when a fixed number of decimal places is required — percentages reported to 2 d.p., pH to 2 d.p., temperatures to 1 d.p. Use signif() for analytical concentrations and masses where significant figures reflect instrument precision.
Syntax
signif(x, digits)signif(x, digits) rounds a number (or vector of numbers) to digits significant figures. Significant figures count from the first non-zero digit, regardless of the position of the decimal point. Use signif() when the relative precision of a measurement matters — which is the case for most analytical chemistry results.
Store intermediate calculated values at full precision. Call signif() only inside cat() when displaying a final result. Rounding intermediate values introduces accumulating errors in multi-step pharmaceutical calculations.
# ✓ Correct — full precision stored, rounded only when printed
C2_ug_ml <- (absorbance - std_intercept) / std_slope
cat("Concentration:", signif(C2_ug_ml, 3), "µg/mL\n")
# ✗ Avoid — rounding before using in further calculations
C2_ug_ml <- signif((absorbance - std_intercept) / std_slope, 3)Examples
Comparing signif() to the raw value
Applying to a whole column or vector
When used inside cat() with a vector, signif() applies to every element. For adding a rounded column to a tibble, use mutate() — but only if the rounded value itself is the final deliverable (e.g., a formatted report column), not if it will be used in further calculations.
signif() vs round() — which to use?
Argument Overview
Required arguments must be included when using a function while optional arguments can be included on demand.
x — number(s) to round numeric | integer Required
A single number or a numeric vector. signif() is vectorised — it applies element-wise to every value in the vector.
Data Types: numeric | integer
digits — number of significant figures integer Required
The number of significant figures to keep. Must be a positive integer.
signif(x, digits = 6)signif(x, digits = 6) shows the default value of digits. If you omit digits, R keeps 6 significant figures. In practice you should always state digits explicitly to match the precision of your method.
A significant figure is any digit from the first non-zero digit onward.
x |
digits |
Result | Explanation |
|---|---|---|---|
31.187 |
3 |
31.2 |
Digits: 3, 1, 2 |
0.004512 |
2 |
0.0045 |
Digits: 4, 5 |
158400 |
3 |
158000 |
Digits: 1, 5, 8 |
Data Types: integer · Must be ≥ 1