get_distinct | R Documentation |
A wrapper around 'dplyr::group_by dplyr::ungroup()'. I use this all the time when I am working with data from REDCap. This is meant to make my life easier and clean up my code.
get_distinct(data, id, ..., fill_direction = "downup")
data |
A data.frame or tibble. |
id |
Unquoted name of grouping variable. Typically a subject or record id. |
... |
A selection of columns. If empty, nothing happens. You can supply bare variable names, select all variables between x and z with x:z, exclude y with -y. For more selection options, see the 'dplyr::select()' documentation. |
fill_direction |
Direction in which to fill missing values. Currently either "down" (the default), "up", "downup" (i.e. first down and then up) or "updown" (first up and then down). |
A tbl_df
library(dplyr)
library(tibble)
df <- tibble::tribble(
~id, ~form, ~age, ~sex, ~ethnicity, ~trt,
1L, "age", 25L, NA, NA, NA,
1L, "sex", NA, "Male", NA, NA,
1L, "race_ethnicity", NA, NA, "Hispanic or Latino", NA,
1L, "treatment", NA, NA, NA, "A",
2L, "age", 32L, NA, NA, NA,
2L, "sex", NA, "Female", NA, NA,
2L, "race_ethnicity", NA, NA, "Not Hispanic or Latino", NA,
2L, "treatment", NA, NA, NA, "B"
)
df
df %>%
get_distinct(data = .,
id = id,
age, sex, ethnicity, trt)
df %>%
get_distinct(data = .,
id = id,
dplyr::starts_with("ag"))
df %>%
get_distinct(data = .,
id = id,
dplyr::one_of("age", "sex"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.