-
Notifications
You must be signed in to change notification settings - Fork 1
/
040-R-solutions-for-common.Rmd
117 lines (49 loc) · 5.43 KB
/
040-R-solutions-for-common.Rmd
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# (PART\*) R solutions for common issues {-}
# R solutions for patient data
A series of independent, self-contained mini examples in R scripts. Most come from questions asked by clinicians. Each is like a stackoverflow Q&A. They are targetted at clinicians or analysts who are relatively new to R. Designed to be modular so that you can use together or in isolation. Encourage you to use [Minimal Reproducible Examples (reprex)](https://stackoverflow.com/help/minimal-reproducible-example) both to help solve issues yourself and when asking questions of colleagues or on stackoverflow.
updated 2022-06-08
To use, either :
1. create a new [RStudio project from the repository](https://github.com/uclh-criu/learning-datascience/blob/master/instructions/03-instructions-if-self-guided.md#1-download-the-course-materials-from-github-into-an-rstudio-project) to view & run the scripts locally
2. just copy & paste the code from Github into RStudio
These examples are in early development and are likely to change, please suggest or submit improvements.
(note to authors : this file is created & overwritten by x-create-readme-book.r)
## [columns-from-measure-names-in-rows-using-pivot_wider.r](https://github.com/andysouth/testuclhbookdown/blob/master/examples-mini/columns-from-measure-names-in-rows-using-pivot_wider.r) {-}
create columns from measure names stored in an existing single column and values in another
## [date-time-formatting.r](https://github.com/andysouth/testuclhbookdown/blob/master/examples-mini/date-time-formatting.r) {-}
convert data to date/time format when it has been read in as just character
## [diagnoses-per-patients-frequency.r](https://github.com/andysouth/testuclhbookdown/blob/master/examples-mini/diagnoses-per-patients-frequency.r) {-}
summarise the frequency of unique diagnoses across patients
## [diagnosis-count.r](https://github.com/andysouth/testuclhbookdown/blob/master/examples-mini/diagnosis-count.r) {-}
count number of unique diagnoses
## [diagnosis-name-search-contains.r](https://github.com/andysouth/testuclhbookdown/blob/master/examples-mini/diagnosis-name-search-contains.r) {-}
search diagnoses to find those that contain one of a number of text fragments
## [diagnosis-name-search-exact.r](https://github.com/andysouth/testuclhbookdown/blob/master/examples-mini/diagnosis-name-search-exact.r) {-}
search diagnoses to find those that exactly match one of a number of strings
## [diagnosis-per-patient-count.r](https://github.com/andysouth/testuclhbookdown/blob/master/examples-mini/diagnosis-per-patient-count.r) {-}
count number of unique diagnoses per patient - optionally add column to original table
## [event-count-per-month-year-patient.r](https://github.com/andysouth/testuclhbookdown/blob/master/examples-mini/event-count-per-month-year-patient.r) {-}
count events per month or year, and patient from a table with columns for patient id and date/time of events
## [event-duration-per-patient.r](https://github.com/andysouth/testuclhbookdown/blob/master/examples-mini/event-duration-per-patient.r) {-}
calculate start, end and duration per patient from a table with columns for patient id and date/time of events
## [event-latest-per-patient.r](https://github.com/andysouth/testuclhbookdown/blob/master/examples-mini/event-latest-per-patient.r) {-}
retain the latest events per patient from a table with columns for patient id and date/time of event
## [join-data-by-patient-id.r](https://github.com/andysouth/testuclhbookdown/blob/master/examples-mini/join-data-by-patient-id.r) {-}
join two tables of data for the same patients
## [measures-summary-per-patient.r](https://github.com/andysouth/testuclhbookdown/blob/master/examples-mini/measures-summary-per-patient.r) {-}
calculate min,max,mean etc. per patient from a table with columns for patient id and measures, and rows per event
## [missing-data-formatting.r](https://github.com/andysouth/testuclhbookdown/blob/master/examples-mini/missing-data-formatting.r) {-}
format missing data values correctly (NA)
## [missing-data-per-patient-count.r](https://github.com/andysouth/testuclhbookdown/blob/master/examples-mini/missing-data-per-patient-count.r) {-}
count number of missing values (NA) per patient
## [missing-data-per-patient-remove.r](https://github.com/andysouth/testuclhbookdown/blob/master/examples-mini/missing-data-per-patient-remove.r) {-}
remove missing values OR patients that have at least one missing value (NA)
## [number-formatting.r](https://github.com/andysouth/testuclhbookdown/blob/master/examples-mini/number-formatting.r) {-}
convert data to number format when it has been read in as character (using as.numeric())
## [patient-count-by-date-from-admission-discharge.r](https://github.com/andysouth/testuclhbookdown/blob/master/examples-mini/patient-count-by-date-from-admission-discharge.r) {-}
count the number of patients per date from a table of admission and discharge dates per patient
## [patient-count.r](https://github.com/andysouth/testuclhbookdown/blob/master/examples-mini/patient-count.r) {-}
count patients when more than one row per patient
## [replace-patient-id.r](https://github.com/andysouth/testuclhbookdown/blob/master/examples-mini/replace-patient-id.r) {-}
to replace a patient identifier column (e.g. MRN) with an index
## [x-create-readme-book.r](https://github.com/andysouth/testuclhbookdown/blob/master/examples-mini/x-create-readme-book.r) {-}
script to create the readme file for the mini examples