{"id":22853018,"url":"https://github.com/vgherard/gsample","last_synced_at":"2025-03-31T07:12:48.652Z","repository":{"id":159807752,"uuid":"330022646","full_name":"vgherard/gsample","owner":"vgherard","description":"Efficient weighted sampling without replacement in R","archived":false,"fork":false,"pushed_at":"2021-01-20T20:40:30.000Z","size":102,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-06T11:53:24.136Z","etag":null,"topics":["random-sampling"],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vgherard.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2021-01-15T21:07:42.000Z","updated_at":"2024-05-09T04:50:32.000Z","dependencies_parsed_at":"2024-02-21T23:00:57.835Z","dependency_job_id":null,"html_url":"https://github.com/vgherard/gsample","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vgherard%2Fgsample","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vgherard%2Fgsample/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vgherard%2Fgsample/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vgherard%2Fgsample/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vgherard","download_url":"https://codeload.github.com/vgherard/gsample/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246429493,"owners_count":20775808,"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":["random-sampling"],"created_at":"2024-12-13T06:10:18.208Z","updated_at":"2025-03-31T07:12:48.646Z","avatar_url":"https://github.com/vgherard.png","language":"R","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# gsample\n\n\u003c!-- badges: start --\u003e\n\u003c!-- badges: end --\u003e\n\n`gsample` offers a drop-in replacement for the R `base::sample()` functions for\nrandom sampling, with considerably better performance for the case of weighted \nsampling without replacement (both from the speed and memory point of view).\n\n## Installation\n\nYou can install `gsample` from [GitHub](https://github.com/vgherard/gsample) \nwith:\n\n``` r\n# install.packages(\"devtools\")\ndevtools::install_github(\"vgherard/gsample\")\n```\n## Example\n\nThe `gsample` API is identical to the one of `base::sample()`:\n\n```{r}\nlibrary(gsample)\nn \u003c- 1e3\nsize \u003c- 1e2\nprob \u003c- exp(rnorm(n, sd = 3))\ngsample.int(n, size, prob = prob)\n```\n\n```{r}\nx \u003c- letters\nsize \u003c- 10\nprob \u003c- exp(rnorm(length(letters), sd = 3))\ngsample(x, size, prob = prob)\n```\n\nHere are some simple benchmark comparisons with `base::sample()`:\n\n```{r, message=FALSE, warning=FALSE}\nlibrary(dplyr)\nlibrary(ggplot2)\nset.seed(840)\nn \u003c- 1e6\nprob \u003c- rexp(n)\n\nbm \u003c- lapply(10 ^ (1:5), function(size) {\n\tbench::mark(\n\t\tgsample.int(n, size, prob = prob),\n\t\tsample.int(n, size, prob = prob),\n\t\tcheck = FALSE\n\t\t) %\u003e%\n\t\tselect(expression, median) %\u003e%\n\t\tmutate(expression = as.character(expression)) %\u003e%\n       \t\tmutate(size = size)\n\t}) \n\nbind_rows(bm) %\u003e%\n\tggplot(aes(x = size, y = 1e3 * median, colour = expression)) +\n\t\tgeom_line() +\n\t\tscale_x_continuous(trans = \"log10\") +\n\t\tscale_y_continuous(\"median (ms)\", trans = \"log10\")\n\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvgherard%2Fgsample","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvgherard%2Fgsample","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvgherard%2Fgsample/lists"}