View source: R/utils-profiles.R
get_profile_of | R Documentation |
Turns implicit missing values into explicit missing values. This is a wrapper
around expand()
, dplyr::full_join()
and replace_na()
that's useful for
completing missing combinations of data.
get_profile_of(data, sources, values_fill = NA)
data |
A data frame. |
sources |
A named vector or list with the values to expand and get profile. |
values_fill |
Optionally, a (scalar) value that specifies what each
This can be a named list if you want to apply different fill values to different value columns. |
A data frame with the expanded grid of the values passed in
sources
and filled as specified in the fill
argument.
complete expand
## Not run:
library(dplyr, warn.conflicts = FALSE)
df <- tibble(
group = c(1:2, 1),
item_id = c(1:2, 2),
item_name = c("a", "b", "b"),
value1 = 1:3,
value2 = 4:6
)
to_get_profile <- list(group = c(1, 2, 3), item_id = c(1, 2))
# This will add the combinations of group 3 with the id of the items
df %>% get_profile_of(sources = to_get_profile)
# You can also choose to fill in missing values
# This only fill with "Unknown" the NA values of the column item_name
df %>% get_profile_of(
sources = to_get_profile,
values_fill = list(item_name = "Unknown")
)
# Replace all NAs with "Unkwnon"
df %>% get_profile_of(sources = to_get_profile, values_fill = "Unknown")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.