generated from opensafely/research-template
/
sex_missing.R
37 lines (30 loc) · 1.25 KB
/
sex_missing.R
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
####################################################################################################
# This script:
# - Produces counts of patients prescribed opioids by demographic characteristics (Apr-Jun 2022)
# - Both overall in full population, and people without a cancer diagnosis
# - Both crude and age/sex standardised
####################################################################################################
## For running locally only
# setwd("C:/Users/aschaffer/OneDrive - Nexus365/Documents/GitHub/opioids-covid-research")
# getwd()
## Import libraries
library('tidyverse')
library('lubridate')
library('reshape2')
library('here')
library('fs')
## Custom functions
source(here("analysis", "lib", "custom_functions.R"))
## Create directories if needed
dir_create(here::here("output", "tables"), showWarnings = FALSE, recurse = TRUE)
dir_create(here::here("output", "data"), showWarnings = FALSE, recurse = TRUE)
## Read in data
cohort <- read_csv(here::here("output", "data", "dataset_missing.csv.gz"))
cohort_sex <- cohort %>%
mutate(total = rounding(n())) %>%
group_by(sex) %>%
summarise(
count = rounding(n())
)
write.csv(cohort_sex, here::here("output", "tables", "cohort_sex_missing.csv"),
row.names = FALSE)