encodefrom {crosswalkr} | R Documentation |
Encode data frame column using external crosswalk file.
Description
Encode data frame column using external crosswalk file.
Usage
encodefrom(
.data,
var,
cw_file,
raw,
clean,
label,
delimiter = NULL,
sheet = NULL,
case_ignore = TRUE,
ignore_tibble = FALSE
)
encodefrom_(
.data,
var,
cw_file,
raw,
clean,
label,
delimiter = NULL,
sheet = NULL,
case_ignore = TRUE,
ignore_tibble = FALSE
)
Arguments
.data |
Data frame or tbl_df |
var |
Column name of vector to be encoded |
cw_file |
Either data frame object or string with path to
external crosswalk file, including path, which has columns
representing |
raw |
Name of column in |
clean |
Name of column in |
label |
Name of column in |
delimiter |
String delimiter used to parse
|
sheet |
Specify sheet if |
case_ignore |
Ignore case when matching current ( |
ignore_tibble |
Ignore |
Value
Vector that is either a factor or labelled, depending on data input and options
Functions
-
encodefrom_
: Standard evaluation version ofencodefrom
(var
,raw
,clean
, andlabel
must be strings when using this version)
Examples
df <- data.frame(state = c('Kentucky','Tennessee','Virginia'),
stfips = c(21,47,51),
cenregnm = c('South','South','South'))
df_tbl <- tibble::as_tibble(df)
cw <- get(data(stcrosswalk))
df$state2 <- encodefrom(df, state, cw, stname, stfips, stabbr)
df_tbl$state2 <- encodefrom(df_tbl, state, cw, stname, stfips, stabbr)
df_tbl$state3 <- encodefrom(df_tbl, state, cw, stname, stfips, stabbr,
ignore_tibble = TRUE)
haven::as_factor(df_tbl)
haven::zap_labels(df_tbl)