{"id":26638171,"url":"https://github.com/multimeric/maskr","last_synced_at":"2025-03-24T17:25:26.434Z","repository":{"id":283602078,"uuid":"615765477","full_name":"multimeric/maskr","owner":"multimeric","description":"Defines a masked array type in R, which allows you to hide a subsection of the array","archived":false,"fork":false,"pushed_at":"2023-03-27T14:21:20.000Z","size":22,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-21T05:23:35.230Z","etag":null,"topics":["rstats"],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/multimeric.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"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":"2023-03-18T16:06:13.000Z","updated_at":"2024-10-02T16:40:25.000Z","dependencies_parsed_at":"2025-03-21T05:33:38.488Z","dependency_job_id":null,"html_url":"https://github.com/multimeric/maskr","commit_stats":null,"previous_names":["multimeric/maskr"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/multimeric%2Fmaskr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/multimeric%2Fmaskr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/multimeric%2Fmaskr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/multimeric%2Fmaskr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/multimeric","download_url":"https://codeload.github.com/multimeric/maskr/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245316951,"owners_count":20595531,"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":["rstats"],"created_at":"2025-03-24T17:25:26.053Z","updated_at":"2025-03-24T17:25:26.421Z","avatar_url":"https://github.com/multimeric.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n```\n\n# maskr\n\n\u003c!-- badges: start --\u003e\n[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)\n[![CRAN status](https://www.r-pkg.org/badges/version/maskr)](https://CRAN.R-project.org/package=maskr)\n\u003c!-- badges: end --\u003e\n\nThe `maskr` package provides a masked array type, which is either a vector, array, matrix, or data frame which has a *mask*.\nThe mask is a list of indices, one for each axis of the array, which defines the parts of the array to show. \nAll other parts then become invisible.\n\n## Installation\n\nYou can install the development version of maskr from [GitHub](https://github.com/) with:\n\n``` r\n# install.packages(\"remotes\")\nremotes::install_github(\"multimeric/maskr\")\n```\n\n## Basics\n\nYou can create a `MaskedArray` using the constructor function, which takes firstly\nthe array to mask, and secondly a list of mask vectors, one for each dimension of the array.\nFor a masked vector, the mask is a list of one vector.\n\nHere we define an inner array with 10 elements, but our mask, which is a vector of indices to show, hides `\"a\"` and `\"j\"`:\n\n```{r example}\nx = maskr::MaskedArray(letters[1:10], masks=list(2:9))\nx\n```\n\nFor most purposes, the array acts the same as `c(\"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\")`:\n\n```{r}\nlength(x)\n```\n```{r}\nx[[1]]\n```\n\nHowever, we can unmask the array the return to the original form:\n\n```{r}\nmaskr::unmask(x)\n```\n\n## Use Cases\n\nOne use case for `maskr` is hiding some kind of bad data, like outliers.\n\nFor example, let's start with some data that includes two outliers\n\n```{r}\nset.seed(1)\nx = c(\n  rnorm(10),\n  rnorm(2, mean=2)\n)\nx\n```\n\nWe could identify these outliers using some kind of test. \nIn this case we test that all the values come from from a $N(0, 1)$ distribution:\n\n```{r}\noutliers = pnorm(x, lower.tail = F) \u003c 0.05\noutliers\n```\n\nThen we can use that outlier list as a mask. \nNote that logical vectors are also legal masks!\n\n```{r}\nmasked = maskr::MaskedArray(x, mask = list(!outliers))\nmasked\n```\n\nWe can then find the mean of the non-outliers directly on the masked array:\n\n```{r}\nmean(masked)\n```\n\n## Subsetting\n\nAnother useful feature of `maskr` is that, when you subset an array, the mask shrinks to hide the excluded elements. \nLet's define `x` as in the first section:\n\n```{r}\nx = maskr::MaskedArray(letters[1:10], masks=list(2:9))\nx[5:6]\n```\n\nNotice how, the resulting object is still a length-10 vector, but now all but 2 items are hidden.\nWhat this means, is that you can take a sequence of slices from the array:\n\n```{r}\ny = x[-1][-1][-1]\n```\n\nWe can compute the final subset:\n```{r}\nmaskr::apply_mask(y)\n```\nBut also revert the mask:\n```{r}\nmaskr::unmask(y)\n```\n\n## Multidimensional Arrays\n\nWe can mask a matrix. If we do, the mask needs to be a list of two vectors:\n\n```{r}\nx = maskr::MaskedArray(matrix(rnorm(n=16), nrow=4), list(1:2, 2:3))\nx\n```\n```{r}\nmaskr::apply_mask(x)\n```\n\nWe can also mask a `data.frame` in the same way. \nNote that we can use a character vector to select certain columns, as you might expect:\n\n```{r}\nx = maskr::MaskedArray(iris, list(10:15, c(\"Petal.Length\", \"Sepal.Length\")))\nmaskr::apply_mask(x)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmultimeric%2Fmaskr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmultimeric%2Fmaskr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmultimeric%2Fmaskr/lists"}