{
  "name": "Ways to index an R array and what each returns",
  "description": "Compiled from the R reference manual pages for array and Extract and the An Introduction to R manual: each indexing form for a multidimensional R array, its syntax, and the documented rule that governs the result. Syntax examples use the three-dimensional scores array from the guide.",
  "page": "https://casrai.org/guides/array-in-r",
  "publisher": "CASRAI",
  "license": "https://creativecommons.org/licenses/by/4.0/",
  "dateModified": "2026-11-17T10:14:11Z",
  "temporalCoverage": null,
  "spatialCoverage": null,
  "columns": [
    {
      "name": "Indexing form",
      "unit": "",
      "description": ""
    },
    {
      "name": "Example syntax",
      "unit": "",
      "description": ""
    },
    {
      "name": "Documented behaviour",
      "unit": "",
      "description": ""
    },
    {
      "name": "Source page",
      "unit": "",
      "description": ""
    }
  ],
  "rows": [
    {
      "Indexing form": "One index per dimension",
      "Example syntax": "scores[\"S2\", \"t3\", \"treated\"]",
      "Documented behaviour": "Selects one cell; an empty index selects the whole range of that dimension (a[2,,] fixes the first index)",
      "Source page": "An Introduction to R, arrays"
    },
    {
      "Indexing form": "Negative integers",
      "Example syntax": "scores[-1, , ]",
      "Documented behaviour": "Leaves the named elements or slices out of the selection",
      "Source page": "R reference: Extract"
    },
    {
      "Indexing form": "Numeric index matrix",
      "Example syntax": "x[i] where i has one column per dimension",
      "Documented behaviour": "Extracts or replaces the addressed cells; negative values not allowed, zero rows ignored, NA rows give NA",
      "Source page": "An Introduction to R, arrays; R reference: Extract"
    },
    {
      "Indexing form": "Character index matrix",
      "Example syntax": "x[m] where m is a character matrix",
      "Documented behaviour": "Works only if the array has dimnames; empty or NA indices match no name",
      "Source page": "R reference: Extract"
    },
    {
      "Indexing form": "drop argument",
      "Example syntax": "scores[, , \"treated\", drop = FALSE]",
      "Documented behaviour": "With drop = TRUE the result is coerced to the lowest possible dimension; applies to extraction only, not replacement",
      "Source page": "R reference: Extract"
    }
  ],
  "sources": [
    {
      "title": "R Core Team: Extract (Extract or Replace Parts of an Object)",
      "url": "https://stat.ethz.ch/R-manual/R-devel/library/base/html/Extract.html",
      "accessed": "2026-11-17"
    },
    {
      "title": "R Core Team: An Introduction to R",
      "url": "https://cran.r-project.org/doc/manuals/r-release/R-intro.html",
      "accessed": "2026-11-17"
    },
    {
      "title": "R Core Team: array (Multi-way Arrays)",
      "url": "https://stat.ethz.ch/R-manual/R-devel/library/base/html/array.html",
      "accessed": "2026-11-17"
    }
  ]
}