get_profile_of: Complete a data frame with missing combinations of data

View source: R/utils-profiles.R

get_profile_ofR Documentation

Complete a data frame with missing combinations of data

Description

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.

Usage

get_profile_of(data, sources, values_fill = NA)

Arguments

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 value should be filled in with when missing.

This can be a named list if you want to apply different fill values to different value columns.

Value

A data frame with the expanded grid of the values passed in sources and filled as specified in the fill argument.

See Also

complete expand

Examples

## 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)

saezlab/decoupleR documentation built on Oct. 21, 2024, 8:47 a.m.