{"id":28063718,"url":"https://github.com/extendr/mdl","last_synced_at":"2025-05-12T12:18:57.199Z","repository":{"id":256100952,"uuid":"847418779","full_name":"extendr/mdl","owner":"extendr","description":"An opinionated and performant reimagining of model matrices using rust","archived":false,"fork":false,"pushed_at":"2025-04-15T20:57:49.000Z","size":2069,"stargazers_count":6,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-05-12T12:18:46.697Z","etag":null,"topics":["extendr","machine-learning","rstats","rust"],"latest_commit_sha":null,"homepage":"https://extendr.github.io/mdl/","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/extendr.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":".github/SUPPORT.md","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-08-25T19:07:36.000Z","updated_at":"2025-04-17T15:39:39.000Z","dependencies_parsed_at":"2025-04-21T13:01:48.322Z","dependency_job_id":null,"html_url":"https://github.com/extendr/mdl","commit_stats":null,"previous_names":["simonpcouch/mdl","extendr/mdl"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/extendr%2Fmdl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/extendr%2Fmdl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/extendr%2Fmdl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/extendr%2Fmdl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/extendr","download_url":"https://codeload.github.com/extendr/mdl/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253736105,"owners_count":21955786,"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":["extendr","machine-learning","rstats","rust"],"created_at":"2025-05-12T12:18:56.727Z","updated_at":"2025-05-12T12:18:57.182Z","avatar_url":"https://github.com/extendr.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# mdl\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/mdl)](https://CRAN.R-project.org/package=mdl)\n\u003c!-- badges: end --\u003e\n\nmdl implements an opinionated and performant reimagining of model matrices. The package supplies one function, `mdl::mtrx()` (read: \"model matrix\"), that takes in a formula and data frame and outputs a numeric matrix. Compared to its base R friend `model.matrix()`, it's _really_ fast.\n\n**This package is highly experimental. Interpret results with caution!**\n\n## Installation\n\nYou can install the development version of mdl like so:\n\n``` r\n# install.packages(\"mdl\")\npak::pak(\"simonpcouch/mdl\")\n```\n\n## Example\n\nThe output of `mdl::mtrx()` looks a lot like that from `model.matrix()`:\n\n```{r}\n# convert to factor to demonstrate dummy variable creations\nmtcars$cyl \u003c- as.factor(mtcars$cyl)\n\nhead(\n  mdl::mtrx(mpg ~ ., mtcars)\n)\n```\n\nCompared to `model.matrix()`, `mdl::mtrx()` is sort of a glorified `as.matrix()` data frame method. More specifically:\n\n* Does not accept formulae with inlined functions (like `-` or `*`).\n* Never drops rows (and thus doesn't accept an `na.action`).\n* Assumes that factors levels are encoded as they're intended (i.e. `drop.unused.levels` and `xlev` are not accepted).\n\nIt's quite a bit faster for smaller data sets:\n\n```{r}\nbench::mark(\n  mdl::mtrx(mpg ~ ., mtcars),\n  model.matrix(mpg ~ ., mtcars),\n  check = FALSE\n)\n```\n\nThe factor of speedup isn't so drastic for larger datasets and datasets with more factors, but it is still quite substantial:\n\n```{r}\nfor (p in c(\"vs\", \"am\", \"gear\", \"carb\")) {\n  mtcars[[p]] \u003c- as.factor(mtcars[[p]])\n}\n\nbench::mark(\n  mdl::mtrx(mpg ~ ., mtcars[rep(1:32, 1e5), ]),\n  model.matrix(mpg ~ ., mtcars[rep(1:32, 1e5), ]),\n  check = FALSE\n)\n```\n\nCheck out [this article](https://github.com/simonpcouch/mdl/blob/main/vignettes/articles/plain-r.Rmd) for more detailed benchmarks.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fextendr%2Fmdl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fextendr%2Fmdl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fextendr%2Fmdl/lists"}