View source: R/quest_functions.R
make.dummy | R Documentation |
make.dummy
creates dummy columns (i.e., dichotomous numeric vectors
coded 0 and 1) from logical conditions. If you want to make logical
conditions from columns of a data.frame, you will need to call the data.frame
and its columns explicitly as this function does not use non-standard
evaluation.
make.dummy(..., rtn.lgl = FALSE)
... |
logical conditions that evaluate to logical vectors of the same length. If the logical vectors are not the same length, an error is returned. The names of the arguments are the colnames in the return object. If unnamed, then default R data.frame naming is used, which can get ugly. |
rtn.lgl |
logical vector of length 1 specifying whether the dummy columns should be logical vectors (TRUE) rather than numeric vectors (FALSE). |
data.frame of dummy columns based on the logical conditions n
...
. If rtn.lgl
= TRUE, then the columns are logical vectors.
If out.lgl
= FALSE, then the columns are numeric vectors where 0 =
FALSE and 1 = TRUE. The colnames are the names of the arguments in
...
. If not specified, then default data.frame names are created
from the logical conditions themselves (which can get ugly).
make.dumNA
make.dummy(attitude$"rating" > 50) # ugly colnames
make.dummy("rating_50plus" = attitude$"rating" > 50,
"advance_50minus" = attitude$"advance" < 50)
make.dummy("rating_50plus" = attitude$"rating" > 50,
"advance_50minus" = attitude$"advance" < 50, rtn.lgl = TRUE)
## Not run:
make.dummy("rating_50plus" = attitude$"rating" > 50,
"mpg_20plus" = mtcars$"mpg" > 20)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.