A zero weight still counts in the ordinary mean
Input and settings
Values: 10 100 / Weights: 1 0
Expected result
Count 2 / Mean 55 / Median 55 Weight sum 1 / Weighted mean 10
Calculate mean, median, population and sample standard deviations, and weighted mean. Aggregate decimals exactly, then copy or save a JSON report.
Separate numbers with line breaks, spaces or tabs. Use plain digits, decimal points, signs or e notation; commas are not supported. Optional weights must match the numbers in count and order.
Each UTF-8 input: 1 MB and 10,000 values. Each token: 64 characters, up to 12 fractional decimal places, exponent -18 to 18, absolute value at most 10^18. JSON output: 16,000 bytes. Inputs and results are neither stored nor sent.
Use a zero weight and a one-value dataset to distinguish ordinary means, weighted means and sample metrics.
Example buttons replace the inputs and settings above and calculate. Restore previous input steps back one example at a time. After trying multiple examples, repeat restore to return to your original input. This history is lost when the page closes.
Values: 10 100 / Weights: 1 0
Count 2 / Mean 55 / Median 55 Weight sum 1 / Weighted mean 10
Values: -5 / Weights: empty
Count 1 / Mean and median −5 / Population variance and deviation 0 Sample variance and deviation: undefined (JSON null)
The ordinary mean is (10+100)÷2=55. The weighted mean is (10×1+100×0)÷1=10. Weights affect only the weighted mean: count, median and ordinary variance still include zero-weight values. Population variance divides by n and sample variance by n−1, so the one-value sample metrics are undefined rather than zero.
Separate values and optional weights with whitespace. Each input is limited to 1,000,000 UTF-8 bytes; values to 10,000; each number to 64 characters, magnitude 10¹⁸, effective twelve-place fractional precision and exponent −18 to 18. Weights must match the value count, be non-negative and have a positive sum. Results round to twelve decimal places; JSON is capped at 16,000 bytes. A tiny variance may round to zero while deviation from the unrounded variance remains positive. Weighted variance and confidence intervals are not calculated.
Verification: hand calculations give 55 and 10. Existing functions check null sample metrics for one value and rejection of mismatched/all-zero weights. Browser checks cover real Worker output, JSON downloads and restoration after two examples.
For the example 1, 2, 3, 4, mean and median are 2.5, population variance is 1.25, and sample variance is about 1.666666666667. Weights 1, 1, 2, 2 give a weighted mean of about 2.833333333333.
Population variance divides the sum of squared deviations by n; sample variance divides by n−1. Their square roots are the population and sample standard deviations. With one number, sample variance and sample standard deviation are unavailable and become null in JSON.
Weighted mean divides the sum of number × weight by the sum of weights. Weights must be nonnegative and their sum must be positive. Leave weights empty for ordinary statistics; weight sum and weighted mean then become null. Ordinary mean, variance and standard deviation do not use the weights.
Decimals are scaled to integers for exact aggregation. Results are rounded to at most 12 decimal places; exact halfway cases round away from zero. Trailing zeros are omitted. JSON numeric results are decimal strings to retain precision; only count is a JSON number. Standard deviations use the exact variance before rounding.
Editing cancels in-progress work and clears the old result. Cancel retains the inputs; Reset clears numbers, weights and result. JSON is saved as UTF-8 without a BOM or added trailing newline.
Use population standard deviation for the entire population and sample standard deviation for a sample from a larger population. Sample statistics need at least two numbers.
Yes. Ordinary statistics give every input equal weight. Weighted mean uses the corresponding weights separately. A zero-weight number still participates in ordinary statistics.
The tool reports an error instead of silently rounding the input. Exponent notation has the same magnitude and fractional-place limits. Thousands separators such as 1,000 are not accepted.
Share only the tool name and public URL. Your input and results are not included.
Keep any content you need before clearing. This tool does not autosave inputs or results. Reloading or closing the page, clearing inputs or resetting may discard your work.
Favorites and language preferences are stored separately and may be lost when site data is cleared. Tool resets and site-data deletion do not delete files already downloaded to your device.