knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/"
  # out.width = "100%"
)

recodeR

The goal of recodeR is to make recoding super easy when you have a mapping table. I often found myself using the dplyr::case_when function for recoding and it can look super messy real fast when you have a lot of categories to be recoded. Hence, recodeR was born!

My primary use for this package is when I prepare a reference sample and control tables for systhesising microdata. This is a common problem that microsimulation modellers and agent-based modellers would face in the data preparation phase.

Installation

You can install this package using the following commands in R with the remotes package.

remotes::install_github("asiripanich/recodeR")

Example

This is a basic example which shows you how to solve a common problem with recoding:

library(recodeR)
## basic example code

x <- data.frame(
    id = 1:10,
    gender = sample(c("m", "f", "fe"), 10, replace = TRUE),
    labour = sample(c("employed, fulltime", "employed, part-time", "unemployed"), 10, replace = TRUE)
  )
print(x)

my_table <- data.frame(variable = c(rep("gender",3), rep("labour", 3)),
                       category = c("m", "f", "fe",
                                    "employed, fulltime", "employed, part-time", "unemployed"),
                       new_category = c("male", "female", "female",
                                        "employed", "employed", "unemployed"))
print(my_table)

x_new <- recodeR::recode(x = x, table = my_table, verbose = TRUE)
print(x_new)


asiripanich/recodeR documentation built on Nov. 3, 2019, 1:58 p.m.