ys_factors | R Documentation |
This function works like ys_add_factors()
with the difference that
the original columns become factors (retaining the original column names)
and the original columns are retained with a suffix. You can think of this
as a more convenient form of ys_add_factors(..., .suffix = "")
.
ys_factors(data, spec, ..., .keep_values = TRUE, .suffix = "_v")
data |
the data set to modify |
spec |
a yspec object |
... |
unquoted column names for modification; passing nothing through
|
.keep_values |
logical; if |
.suffix |
a suffix to be added to original columns (holding values). |
Factor conversion will only take place on source columns that aren't
already factors. That is, if a column in data
is already a factor, it
will be ignored. This means the function can be called multiple times on
the same input data, but once a column is converted to factor, it will
cannot be converted again in subsequent calls.
The original data frame is returned with columns converted to factors and (possibly) additional columns storing values.
ys_add_factors()
library(dplyr)
spec <- ys_help$spec()
data <- ys_help$data()
data <- ys_factors(data, spec)
head(data, 5)
spec$EVID
count(data, EVID, EVID_v)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.