R/experimental.R
drop_category.Rd
Converts a vector object to a non-categorical object, typically a column in a data frame. The categories come from valid values present in the object and are suppressed from an associated data dictionary (when present).
drop_category(x)
object to be coerced.
A R object.
{
library(dplyr)
###### Example 1: use madshapR_examples provided by the package
dataset <-
madshapR_examples$`dataset_example` %>%
mutate(prg_ever_cat = as_category(prg_ever)) %>%
mutate(prg_ever_no_cat = drop_category(prg_ever))
head(dataset[c("prg_ever_cat","prg_ever_no_cat")])
###### Example 2: any data frame can be a dataset
iris_no_cat <-
tibble(iris) %>% mutate(Species = drop_category(Species))
head(iris_no_cat)
}
#> # A tibble: 6 × 5
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> <dbl> <dbl> <dbl> <dbl> <chr>
#> 1 5.1 3.5 1.4 0.2 setosa
#> 2 4.9 3 1.4 0.2 setosa
#> 3 4.7 3.2 1.3 0.2 setosa
#> 4 4.6 3.1 1.5 0.2 setosa
#> 5 5 3.6 1.4 0.2 setosa
#> 6 5.4 3.9 1.7 0.4 setosa