-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_functions.R
69 lines (42 loc) · 1.46 KB
/
data_functions.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
library(readxl)
library(dplyr)
allPatients <- read_excel("data.xlsx", sheet = "All")
# Functions ---------------------------------------------------------------
dataFunction <- function(data){
countData <- data %>%
mutate(A = smi_count - (smi_cpa_combined + mental_health_patients_smi),
B = cpa_count - smi_cpa_combined,
C = mental_health_patients - mental_health_patients_smi,
`A&B` = smi_cpa_combined,
`A&C` = mental_health_patients_smi,
AllSMI = A+`A&B`+`A&C`
) %>%
arrange(PCN) %>%
mutate(Group = PCN)
return(countData)
}
totalDataFunction <- function(data){
countData <- data %>%
summarise_if(is.numeric, sum, na.rm = TRUE) %>%
mutate(CCG = "Total",
PCN = "Total") %>%
arrange(PCN) %>%
mutate(Group = PCN)
return(countData)
}
# All Patients (regardless of activity) -------------------------------------------
allPatientsData <- dataFunction(allPatients)
allPatientsTotal <- totalDataFunction(allPatientsData)
# Rename and group CCG data -----------------------------------------------
# Rename CCG, PCN and Total to Group to make it generic for a later function to read
CCG_Function <- function(data){
CCGData <- data %>%
select(-PCN, -Group) %>%
group_by(CCG) %>%
arrange(CCG) %>%
summarise_all(list(sum)) %>%
select(Group = CCG,
everything())
return(CCGData)
}
allPatientsDataCCG <- CCG_Function(allPatientsData)