{"id":24529909,"url":"https://github.com/mschubert/narray","last_synced_at":"2025-04-09T22:19:20.154Z","repository":{"id":56934951,"uuid":"70340766","full_name":"mschubert/narray","owner":"mschubert","description":"R package for subset- and name-aware array utility functions","archived":false,"fork":false,"pushed_at":"2025-01-20T09:14:26.000Z","size":304,"stargazers_count":26,"open_issues_count":5,"forks_count":1,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-02T12:55:10.638Z","etag":null,"topics":["array","cran","r-package","utility"],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mschubert.png","metadata":{"files":{"readme":"README.md","changelog":"NEWS.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-10-08T15:36:08.000Z","updated_at":"2025-03-22T11:20:25.000Z","dependencies_parsed_at":"2025-01-31T02:34:31.255Z","dependency_job_id":"840c80d3-5c93-4a96-b669-12e4e7aea994","html_url":"https://github.com/mschubert/narray","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mschubert%2Fnarray","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mschubert%2Fnarray/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mschubert%2Fnarray/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mschubert%2Fnarray/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mschubert","download_url":"https://codeload.github.com/mschubert/narray/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248119464,"owners_count":21050777,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["array","cran","r-package","utility"],"created_at":"2025-01-22T07:53:03.392Z","updated_at":"2025-04-09T22:19:20.131Z","avatar_url":"https://github.com/mschubert.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"narray :: Array and Matrix processing\n=====================================\n\n[![CRAN version](https://www.r-pkg.org/badges/version/narray)](https://cran.r-project.org/package=narray)\n[![Build Status](https://github.com/mschubert/narray/actions/workflows/check-standard.yaml/badge.svg)](https://github.com/mschubert/narray/actions)\n[![CRAN downloads](https://cranlogs.r-pkg.org/badges/narray)](http://cran.rstudio.com/web/packages/narray/index.html)\n\nThis package provides consistent utility functions for array programming with\narbitrary dimensions (summary below).\n\nWe recommend to reference functions using the package namespace or\nloading the package into its own namespace to not shadow base R\nfunctions. The latter can be done using [`box`](https://github.com/klmr/box) or\n[`import`](https://github.com/rticulate/import).\n\n```r\n# do not use library() or require()\n\n# example referencing the package namespace\nnarray::stack(...)\n\n# example using `box`\nbox::use(narray)\nnarray$stack(...)\n```\n\nStacking and splitting\n----------------------\n\n`stack()` is like `cbind`/`rbind`, but along arbitrary axes, and taking care of (1) names \nalong each dimension and (2) padding partial matching arrays.\n\n![stack-schema](vignettes/stack.png)\n\n```r\nA = matrix(1:4, nrow=2, ncol=2, dimnames=list(c('a','b'),c('x','y')))\nB = matrix(5:6, nrow=2, ncol=1, dimnames=list(c('b','a'),'z'))\n\nC = stack(A, B, along=2)\n#    x y z\n#  a 1 3 6   # B is stacked correctly according to its names\n#  b 2 4 5\n\nD = stack(m=A, n=C, along=3) # we can also introduce new dimensions\n# , , m          , , n\n#\n#   x y  z         x y z\n# a 1 3 NA       a 1 3 6\n# b 2 4 NA       b 2 4 5\n```\n\n`split()` splits an array along a given axis; can do each element or defined subsets.\n\n![split](vignettes/split.png)\n\n```r\nsplit(C, along=2, subsets=c('s1','s1','s2'))\n# $s1          $s2\n#   x y          z   # each subset is split into a separate array\n# a 1 3        a 6   # use drop=TRUE to get a vector for s2\n# b 2 4        b 5\n```\n\nMapping functions on arrays\n---------------------------\n\nLike `apply`, but not reordering array dimensions and allowing to specify \nsubsets that the function should be applied on. The function must either return\na vector of the same length as the input (returns matrix of same dimension) or\nof length 1 (drops current dimension or returns subsets).\n\n![map-schema](vignettes/map.png)\n\n```r\nmap(C, along=2, function(x) x*2) # return same length vector\n#   x y  z\n# a 2 6 12\n# b 4 8 10\n\nmap(C, along=2, mean, subsets=c('s1', 's1', 's2')) # summarize each subset to scalar\n#   s1 s2\n# a  2  6\n# b  3  5\n```\n\nWe can also index multiple arrays using the `lambda` function. If the result\nis a scalar we will get back an array, and an index with result column otherwise.\n\n```r\ndot = function(x, y) sum(x * y)\nlambda(~ dot(A, B), along=c(A=1, B=2))\n#    z\n# a 23   # the same as A %*% B\n# b 34\n\nlambda(~ dot(A, B), along=c(A=1, B=2), simplify=FALSE)\n#   A B result\n# 1 a z     23\n# 2 b z     34\n```\n\nIntersecting\n------------\n\nTakes a number of arrays, intersects their names along a given dimension,\nand returns sub-arrays that match in their names; `intersect_list` takes \na list of arrays and returns a list of subsets.\n\n![intersect-schema](vignettes/intersect.png)\n\n```r\nE = matrix(1:6, nrow=3, dimnames=list(c('a','b','d'), c('x','y')))\nF = matrix(7:9, nrow=3, dimnames=list(c('b','a','c'), 'z'))\n\nintersect(E, F, along=1)\n# \u003e E        \u003e F\n#   x y        z\n# a 1 4      a 8\n# b 2 5      b 7\n```\n\nConverting to and from `data.frame`s\n------------------------------------\n\n`construct()` takes a data frame and a formula specifying dependent (values) and independent\n(axes) of the resulting array.\n\n![construct-schema](vignettes/construct.png)\n\n```r\nDF = data.frame(k1=rep(letters[1:3],2), k2=rep(letters[24:25],3), v=1:6)[-6,]\nconstruct(v ~ k1 + k2, data=DF)\n#   x  y\n# a 1  4\n# b 5  2\n# c 3 NA\n```\n\nMasks from factors and lists\n----------------------------\n\nTakes either a factor or a list of vectors and creates a binary matrix \nspecifying whether each element is present.\n\n![mask-schema](vignettes/mask.png)\n\n```r\nG = list(a='e1', b=c('e1','e2'), c='e2')\nmask(G)\n#      e1    e2\n# a  TRUE FALSE\n# b  TRUE  TRUE\n# c FALSE  TRUE\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmschubert%2Fnarray","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmschubert%2Fnarray","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmschubert%2Fnarray/lists"}