{
  "name": "Weighted-mean functions in R compared: weights argument, weight length and return value",
  "description": "Compares the free R functions that compute weighted means or weighted centres: weighted.mean in stats, colWeightedMeans and rowWeightedMeans in matrixStats, and cov.wt in stats. Compiled from the R stats manual pages and the CRAN matrixStats reference manual, giving the weights argument, the required weight length and what each returns.",
  "page": "https://casrai.org/guides/weighted-mean-in-r",
  "publisher": "CASRAI",
  "license": "https://creativecommons.org/licenses/by/4.0/",
  "dateModified": "2026-11-18T15:10:00Z",
  "temporalCoverage": "2026",
  "spatialCoverage": null,
  "columns": [
    {
      "name": "Function",
      "unit": "",
      "description": ""
    },
    {
      "name": "Package",
      "unit": "",
      "description": ""
    },
    {
      "name": "Weights argument",
      "unit": "",
      "description": ""
    },
    {
      "name": "Required weight length",
      "unit": "",
      "description": ""
    },
    {
      "name": "Returns / default without weights",
      "unit": "",
      "description": ""
    }
  ],
  "rows": [
    {
      "Function": "weighted.mean",
      "Package": "stats",
      "Weights argument": "w",
      "Required weight length": "Same length as x",
      "Returns / default without weights": "Numeric vector of length one; equal weights if w is omitted"
    },
    {
      "Function": "colWeightedMeans",
      "Package": "matrixStats",
      "Weights argument": "w (default NULL)",
      "Required weight length": "N, one per row of the N x K matrix x",
      "Returns / default without weights": "Weighted mean of each column; falls back to colMeans() if no weights are given"
    },
    {
      "Function": "rowWeightedMeans",
      "Package": "matrixStats",
      "Weights argument": "w (default NULL)",
      "Required weight length": "K, one per column of the N x K matrix x",
      "Returns / default without weights": "Weighted mean of each row; falls back to rowMeans() if no weights are given"
    },
    {
      "Function": "cov.wt",
      "Package": "stats",
      "Weights argument": "wt",
      "Required weight length": "Equal to nrow(x); non-negative, not all zero",
      "Returns / default without weights": "List with cov, center, n.obs, wt and cor; center holds the weighted means when center = TRUE"
    }
  ],
  "sources": [
    {
      "title": "R stats manual: weighted.mean",
      "url": "https://stat.ethz.ch/R-manual/R-devel/library/stats/html/weighted.mean.html",
      "accessed": "2026-11-16"
    },
    {
      "title": "R stats manual: cov.wt",
      "url": "https://stat.ethz.ch/R-manual/R-devel/library/stats/html/cov.wt.html",
      "accessed": "2026-11-16"
    },
    {
      "title": "CRAN matrixStats reference manual",
      "url": "https://cran.r-project.org/web/packages/matrixStats/refman/matrixStats.html",
      "accessed": "2026-11-16"
    }
  ]
}