File: get_profile_of.Rd

package info (click to toggle)
r-bioc-decoupler 2.12.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 2,612 kB
  • sloc: makefile: 5
file content (61 lines) | stat: -rw-r--r-- 1,851 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils-profiles.R
\name{get_profile_of}
\alias{get_profile_of}
\title{Complete a data frame with missing combinations of data}
\usage{
get_profile_of(data, sources, values_fill = NA)
}
\arguments{
\item{data}{A data frame.}

\item{sources}{A named vector or list with the values to expand and get
profile.}

\item{values_fill}{Optionally, a (scalar) value that specifies what each
\code{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
\code{sources} and filled as specified in the \code{fill} argument.
}
\description{
Turns implicit missing values into explicit missing values. This is a wrapper
around \code{\link[tidyr:expand]{expand()}}, \code{\link[dplyr:mutate-joins]{dplyr::full_join()}} and \code{\link[tidyr:replace_na]{replace_na()}} that's useful for
completing missing combinations of data.
}
\examples{
\dontrun{
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")
}
}
\seealso{
\link[tidyr:complete]{complete} \link[tidyr:expand]{expand}
}
\keyword{internal}