# NOT RUN {
# Read in dictionary and coded date examples --------------------
dict <- read.csv(matchmaker_example("spelling-dictionary.csv"),
stringsAsFactors = FALSE)
dat <- read.csv(matchmaker_example("coded-data.csv"),
stringsAsFactors = FALSE)
dat$date <- as.Date(dat$date)
# Clean spelling based on dictionary -----------------------------
dict # show the dict
head(dat) # show the data
res1 <- match_df(dat,
dictionary = dict,
from = "options",
to = "values",
by = "grp")
head(res1)
# Show warnings/errors from each column --------------------------
# Internally, the `match_vec()` function can be quite noisy with warnings for
# various reasons. Thus, by default, the `match_df()` function will keep
# these quiet, but you can have them printed to your console if you use the
# warn = TRUE option:
res1 <- match_df(dat,
dictionary = dict,
from = "options",
to = "values",
by = "grp",
warn = TRUE)
head(res1)
# You can ensure the order of the factors are correct by specifying
# a column that defines order.
dat[] <- lapply(dat, as.factor)
as.list(head(dat))
res2 <- match_df(dat,
dictionary = dict,
from = "options",
to = "values",
by = "grp",
order = "orders")
head(res2)
as.list(head(res2))
# }
Run the code above in your browser using DataLab