filter_extreme: Filter the First or Last Observation for Each By Group

Description Usage Arguments Details Value Author(s) Examples

View source: R/filter_extreme.R

Description

Filters the first or last observation for each by group.

Usage

1
filter_extreme(dataset, by_vars = NULL, order, mode, check_type = "warning")

Arguments

dataset

Input dataset

The variables specified by the order and the by_vars parameter are expected.

by_vars

Grouping variables

Permitted Values: list of variables

order

Sort order

Within each by group the observations are ordered by the specified order.

Permitted Values: list of variables or functions of variables

mode

Selection mode (first or last)

If "first" is specified, the first observation of each by group is included in the output dataset. If "last" is specified, the last observation of each by group is included in the output dataset.

Permitted Values: "first", "last"

check_type

Check uniqueness?

If "warning" or "error" is specified, the specified message is issued if the observations of the input dataset are not unique with respect to the by variables and the order.

Default: "none"

Permitted Values: "none", "warning", "error"

Details

For each group (with respect to the variables specified for the by_vars parameter) the first or last observation (with respect to the order specified for the order parameter and the mode specified for the mode parameter) is included in the output dataset.

Value

A dataset containing the first or last observation of each by group

Author(s)

Stefan Bundfuss

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
library(dplyr, warn.conflict = FALSE)
library(admiral.test)
data("ex")

# Select first dose for each patient
ex %>%
  filter_extreme(
    by_vars = vars(USUBJID),
    order = vars(EXSEQ),
    mode = "first"
  ) %>%
  select(USUBJID, EXSEQ)

# Select highest dose for each patient
ex %>%
  filter_extreme(
    by_vars = vars(USUBJID),
    order = vars(EXDOSE),
    mode = "last",
    check_type = "none"
  ) %>%
  select(USUBJID, EXDOSE)

epijim/admiral documentation built on Feb. 13, 2022, 12:15 a.m.