Adapted dplyr::select() to include calendar dates and ID columns
cg_select.Rd
Adapted dplyr::select() to include calendar dates and ID columns
Arguments
- cg
a chronogram
- ...
passed to
dplyr::select()
Value
a chronogram with selected columns, and the two columns containing calendar dates and participant IDs.
Examples
library(dplyr)
data("built_smallstudy")
cg <- built_smallstudy$chronogram
## keep or drop columns using selection helpers ##-----------------
## here, keep column names containing "dose"
cg_select(cg, contains("dose"))
#> # A tibble: 1,947 × 6
#> # A chronogram: try summary()
#> calendar_date elig_study_id dose_1 date_dose_1 dose_2 date_dose_2
#> * <date> <fct> <fct> <date> <fct> <date>
#> 1 2020-01-01 1 AZD1222 2021-01-05 AZD1222 2021-02-05
#> 2 2020-01-02 1 AZD1222 2021-01-05 AZD1222 2021-02-05
#> 3 2020-01-03 1 AZD1222 2021-01-05 AZD1222 2021-02-05
#> 4 2020-01-04 1 AZD1222 2021-01-05 AZD1222 2021-02-05
#> 5 2020-01-05 1 AZD1222 2021-01-05 AZD1222 2021-02-05
#> 6 2020-01-06 1 AZD1222 2021-01-05 AZD1222 2021-02-05
#> 7 2020-01-07 1 AZD1222 2021-01-05 AZD1222 2021-02-05
#> 8 2020-01-08 1 AZD1222 2021-01-05 AZD1222 2021-02-05
#> 9 2020-01-09 1 AZD1222 2021-01-05 AZD1222 2021-02-05
#> 10 2020-01-10 1 AZD1222 2021-01-05 AZD1222 2021-02-05
#> # ℹ 1,937 more rows
#> # ★ Dates: calendar_date ★ IDs: elig_study_id
#> # ★ metadata: dose_1, date_dose_1, dose_2, date_dose_2
## Or, drop column names containing "dose"
cg_select(cg, ! contains("dose"))
#> # A tibble: 1,947 × 6
#> # A chronogram: try summary()
#> calendar_date elig_study_id age sex serum_Ab_S serum_Ab_N
#> * <date> <fct> <dbl> <fct> <dbl> <dbl>
#> 1 2020-01-01 1 40 F NA NA
#> 2 2020-01-02 1 40 F NA NA
#> 3 2020-01-03 1 40 F NA NA
#> 4 2020-01-04 1 40 F NA NA
#> 5 2020-01-05 1 40 F NA NA
#> 6 2020-01-06 1 40 F NA NA
#> 7 2020-01-07 1 40 F NA NA
#> 8 2020-01-08 1 40 F NA NA
#> 9 2020-01-09 1 40 F NA NA
#> 10 2020-01-10 1 40 F NA NA
#> # ℹ 1,937 more rows
#> # ★ Dates: calendar_date ★ IDs: elig_study_id
#> # ★ metadata: age, sex
## keep or drop columns using exact names ##-----------------------
cg_select(cg, "dose_1")
#> # A tibble: 1,947 × 3
#> # A chronogram: try summary()
#> calendar_date elig_study_id dose_1
#> * <date> <fct> <fct>
#> 1 2020-01-01 1 AZD1222
#> 2 2020-01-02 1 AZD1222
#> 3 2020-01-03 1 AZD1222
#> 4 2020-01-04 1 AZD1222
#> 5 2020-01-05 1 AZD1222
#> 6 2020-01-06 1 AZD1222
#> 7 2020-01-07 1 AZD1222
#> 8 2020-01-08 1 AZD1222
#> 9 2020-01-09 1 AZD1222
#> 10 2020-01-10 1 AZD1222
#> # ℹ 1,937 more rows
#> # ★ Dates: calendar_date ★ IDs: elig_study_id
#> # ★ metadata: dose_1
# or equivalently:
cg_select(cg, dose_1)
#> # A tibble: 1,947 × 3
#> # A chronogram: try summary()
#> calendar_date elig_study_id dose_1
#> * <date> <fct> <fct>
#> 1 2020-01-01 1 AZD1222
#> 2 2020-01-02 1 AZD1222
#> 3 2020-01-03 1 AZD1222
#> 4 2020-01-04 1 AZD1222
#> 5 2020-01-05 1 AZD1222
#> 6 2020-01-06 1 AZD1222
#> 7 2020-01-07 1 AZD1222
#> 8 2020-01-08 1 AZD1222
#> 9 2020-01-09 1 AZD1222
#> 10 2020-01-10 1 AZD1222
#> # ℹ 1,937 more rows
#> # ★ Dates: calendar_date ★ IDs: elig_study_id
#> # ★ metadata: dose_1
# or several selectors together ##---------------------------------
cg_select(cg, dose_1, dose_2)
#> # A tibble: 1,947 × 4
#> # A chronogram: try summary()
#> calendar_date elig_study_id dose_1 dose_2
#> * <date> <fct> <fct> <fct>
#> 1 2020-01-01 1 AZD1222 AZD1222
#> 2 2020-01-02 1 AZD1222 AZD1222
#> 3 2020-01-03 1 AZD1222 AZD1222
#> 4 2020-01-04 1 AZD1222 AZD1222
#> 5 2020-01-05 1 AZD1222 AZD1222
#> 6 2020-01-06 1 AZD1222 AZD1222
#> 7 2020-01-07 1 AZD1222 AZD1222
#> 8 2020-01-08 1 AZD1222 AZD1222
#> 9 2020-01-09 1 AZD1222 AZD1222
#> 10 2020-01-10 1 AZD1222 AZD1222
#> # ℹ 1,937 more rows
#> # ★ Dates: calendar_date ★ IDs: elig_study_id
#> # ★ metadata: dose_1, dose_2
cg_select(cg, contains("dose") & contains("date"))
#> # A tibble: 1,947 × 4
#> # A chronogram: try summary()
#> calendar_date elig_study_id date_dose_1 date_dose_2
#> * <date> <fct> <date> <date>
#> 1 2020-01-01 1 2021-01-05 2021-02-05
#> 2 2020-01-02 1 2021-01-05 2021-02-05
#> 3 2020-01-03 1 2021-01-05 2021-02-05
#> 4 2020-01-04 1 2021-01-05 2021-02-05
#> 5 2020-01-05 1 2021-01-05 2021-02-05
#> 6 2020-01-06 1 2021-01-05 2021-02-05
#> 7 2020-01-07 1 2021-01-05 2021-02-05
#> 8 2020-01-08 1 2021-01-05 2021-02-05
#> 9 2020-01-09 1 2021-01-05 2021-02-05
#> 10 2020-01-10 1 2021-01-05 2021-02-05
#> # ℹ 1,937 more rows
#> # ★ Dates: calendar_date ★ IDs: elig_study_id
#> # ★ metadata: date_dose_1, date_dose_2