View source: R/transforms_fill.R
recode_values | R Documentation |
Recode/Replace values in a data frame column
recode_values(.data, .col, ..., .not_found)
.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. |
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.
A copy of .data with the modified column
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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.