{"id":14068876,"url":"https://github.com/btskinner/crosswalkr","last_synced_at":"2025-09-27T04:31:24.801Z","repository":{"id":56936629,"uuid":"106968265","full_name":"btskinner/crosswalkr","owner":"btskinner","description":"Rename and encode variables using external crosswalk files","archived":false,"fork":false,"pushed_at":"2024-03-11T14:43:25.000Z","size":397,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-04-04T18:10:20.949Z","etag":null,"topics":["crosswalk","encode","labels","r","rename"],"latest_commit_sha":null,"homepage":"https://www.btskinner.io/crosswalkr","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/btskinner.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2017-10-14T22:46:47.000Z","updated_at":"2024-05-13T18:53:29.640Z","dependencies_parsed_at":"2024-05-13T19:04:28.218Z","dependency_job_id":null,"html_url":"https://github.com/btskinner/crosswalkr","commit_stats":{"total_commits":54,"total_committers":4,"mean_commits":13.5,"dds":"0.37037037037037035","last_synced_commit":"b67ed4205d90967161641aef6ab9f1bfb1c3786c"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/btskinner%2Fcrosswalkr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/btskinner%2Fcrosswalkr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/btskinner%2Fcrosswalkr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/btskinner%2Fcrosswalkr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/btskinner","download_url":"https://codeload.github.com/btskinner/crosswalkr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234384355,"owners_count":18823663,"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":["crosswalk","encode","labels","r","rename"],"created_at":"2024-08-13T07:06:27.576Z","updated_at":"2025-09-27T04:31:24.499Z","avatar_url":"https://github.com/btskinner.png","language":"R","readme":"---\ntitle: crosswalkr\noutput: md_document\n---\n\n# crosswalkr \u003cimg src=\"man/figures/logo.png\" align=\"right\" /\u003e\n\n```{r, include = FALSE}\noptions(width = 100)\n```\n\n[![R build\nstatus](https://github.com/btskinner/crosswalkr/workflows/R-CMD-check/badge.svg)](https://github.com/btskinner/crosswalkr/actions)\n[![GitHub release](https://img.shields.io/github/release/btskinner/crosswalkr.svg)](https://github.com/btskinner/crosswalkr)\n[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/crosswalkr)](http://cran.r-project.org/package=crosswalkr)\n\n## Overview\n\nThis package offers a pair of functions, `renamefrom()` and\n `encodefrom()`, for renaming and encoding data frames using external\n crosswalk files. It is especially useful when constructing master\n data sets from multiple smaller data sets that do not name or encode\n variables consistently across files. Based on `renamefrom` and\n `encodefrom` [Stata commands written by Sally Hudson and\n team](https://github.com/slhudson/rename-and-encode).\n\n## Installation\n\nInstall the latest release version from CRAN with\n\n```{r, eval = FALSE}\ninstall.packages('crosswalkr')\n```\n\nInstall the latest development version from Github with\n\n```{r, eval = FALSE}\ndevtools::install_github('btskinner/crosswalkr')\n```\n\n## Usage\n\n```{r, message = FALSE}\nlibrary(crosswalkr)\nlibrary(dplyr)\nlibrary(haven)\n```\n```{r}\n## starting data frame\ndf \u003c- data.frame(state = c('Kentucky','Tennessee','Virginia'),\n                 fips = c(21,47,51),\n                 region = c('South','South','South'))\ndf\n\n## crosswalk with which to convert old names to new names with labels\ncw \u003c- data.frame(old_name = c('state','fips'),\n                 new_name = c('stname','stfips'),\n                 label = c('Full state name', 'FIPS code'))\ncw\n```  \n\n### Renaming\n\nConvert old variable names to new names and add labels from crosswalk. \n\n```{r}\ndf1 \u003c- renamefrom(df, cw_file = cw, raw = old_name, clean = new_name, label = label)\ndf1\n```   \n\nConvert old variable names to new names using old names as labels\n(ignoring labels in crosswalk).\n```{r}\ndf2 \u003c- renamefrom(df, cw_file = cw, raw = old_name, clean = new_name, name_label = TRUE)\ndf2\n```  \n\nConvert old variable names to new names, but keep unmatched old names\nin the data frame.\n```{r}\ndf3 \u003c- renamefrom(df, cw_file = cw, raw = old_name, clean = new_name, drop_extra = FALSE)\ndf3 \n```\n\n### Encoding\n\n```{r}\n\n## starting data frame\ndf \u003c- data.frame(state = c('Kentucky','Tennessee','Virginia'),\n                 stfips = c(21,47,51),\n                 cenregnm = c('South','South','South'))\ndf\n\n## use state crosswalk data file from package\ncw \u003c- get(data(stcrosswalk))\ncw\n```\n\nCreate a new column with factor-encoded values\n```{r}\ndf$state2 \u003c- encodefrom(df, var = state, cw_file = cw, raw = stname, clean = stfips, label = stabbr)\ndf\n```  \n\nCreate a new column with labelled values.\n```{r}\n## convert to tbl_df\ndf \u003c- tibble::as_tibble(df)\ndf$state3 \u003c- encodefrom(df, var = state, cw_file = cw, raw = stname, clean = stfips, label = stabbr)\n```\n\nCreate new column with factor-encoded values (ignores the fact that `df` is a tibble)\n```{r}\ndf$state4 \u003c- encodefrom(df, var = state, cw_file = cw, raw = stname, clean = stfips, label = stabbr, ignore_tibble = TRUE)\n```\n\nShow factors with labels:\n```{r}\nas_factor(df)\n```\nShow factors without labels:\n```{r}\nzap_labels(df)\n```\n","funding_links":[],"categories":["R"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbtskinner%2Fcrosswalkr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbtskinner%2Fcrosswalkr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbtskinner%2Fcrosswalkr/lists"}