recode_values: Recode/Replace values in a data frame column

View source: R/transforms_fill.R

recode_valuesR Documentation

Recode/Replace values in a data frame column

Description

Recode/Replace values in a data frame column

Usage

recode_values(.data, .col, ..., .not_found)

Arguments

.data

A data_frame type object

.col

The unquoted name of the column to recode

...

Name-value pairs of expressions to use in replacement

.not_found

If a value in .col is not in ... , the value to it replace with.

Details

This function is used to change values in a column. The name in the ... argument can be a string or a quoted value. See the examples.

Value

A copy of .data with the modified column

Examples

library(dplyr)
data_frame(ID=1:3,SEX=c("M","F","X")) %>% recode_values(SEX, "M"=1, "F"=2)
data_frame(ID=1:3,SEX=c("M","F","X")) %>% recode_values(SEX, "M"="Male", "F"="Female")
data_frame(ID=1:3,SEX=c("M","F","X")) %>% recode_values(ID, "1"=1101, "2"=1102)
data_frame(ID=1:3,SEX=c("M","F","X")) %>% recode_values(ID, "1"=1101, "2"=1102, .not_found=NA)
data_frame(ID=1:3,SEX=c("M","F","X")) %>% recode_values(ID, "1"=1101, "2"=1102, "4"="not here")

qPharmetra/PMDatR documentation built on April 7, 2024, 5:42 p.m.