-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdata_compile.R
94 lines (80 loc) · 4.02 KB
/
data_compile.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
rm(list=ls())
library(tidyverse)
dir.input="xxx"
dir.output="xxx"
setwd(dir.input)
files=list.files()
tmp=files[grep("AgeSex", files, value=FALSE)]
age.sex=NULL
for(p in 1:length(tmp)){
junk=read.csv(tmp[p]);colnames(junk)=tolower(colnames(junk))
junk[which(junk[,"pts_all"]%in%c(-99,NA,Inf,-999)),"pts_all"]=NA;junk[which(junk[,"pts_ever_severe"]%in%c(-99,NA,Inf,-999)),"pts_ever_severe"]=NA
junk[,"pts_never_severe"]=junk[,"pts_all"]-junk[,"pts_ever_severe"]
junk[which((junk[,"pts_never_severe"]%in%c(-99,NA,Inf,-999))|(junk[,"pts_never_severe"]<0)),"pts_never_severe"]=NA
age.sex=rbind(age.sex,junk)
}
saveRDS(age.sex,paste0(dir.output,"age_sex.RDS"))
tmp=files[grep("ClinicalCourse", files, value=FALSE)]
course=NULL
for(p in 1:length(tmp)){
junk=read.csv(tmp[p]);colnames(junk)=tolower(colnames(junk))
for(ll in 4:10){
junk[which(junk[,ll]%in%c(-99,NA,Inf,-999)),ll]=NA
}
junk[,"pts_never_severe_in_hosp"]=junk[,"pts_all_in_hosp"]-junk[,"pts_ever_severe_in_hosp"]
junk[which(junk[,"pts_never_severe_in_hosp"]<0),"pts_never_severe_in_hosp"]=NA
course=rbind(course,junk)
}
saveRDS(course,paste0(dir.output,"clinical_course.RDS"))
tmp=files[grep("DailyCounts", files, value=FALSE)]
dailycount=NULL
for(p in 1:length(tmp)){
junk=read.csv(tmp[p]);colnames(junk)=tolower(colnames(junk))
for(ll in 4:13){
junk[which(junk[,ll]%in%c(-99,NA,Inf,-999)),ll]=NA
}
junk[,"cumulative_pts_never_severe"]=junk[,"cumulative_pts_all"]-junk[,"cumulative_pts_severe"]
junk[which(junk[,"cumulative_pts_never_severe"]<0),"cumulative_pts_never_severe"]=NA
dailycount=rbind(dailycount,junk)
}
saveRDS(dailycount,paste0(dir.output,"daily_count.RDS"))
tmp=files[grep("DiagProcMed", files, value=FALSE)]
diagnosis=NULL
for(p in 1:length(tmp)){
junk=read.csv(tmp[p]);colnames(junk)=tolower(colnames(junk))
for(ll in 5:24){
junk[which(junk[,ll]%in%c(-99,NA,Inf,-999)),ll]=NA
}
junk[,"pts_never_severe_before_adm"]=junk[,"pts_all_before_adm"]-junk[,"pts_ever_severe_before_adm"]
junk[,"pts_never_severe_since_adm"]=junk[,"pts_all_since_adm"]-junk[,"pts_ever_severe_since_adm"]
junk[,"pts_never_severe_dayn14ton1"]=junk[,"pts_all_dayn14ton1"]-junk[,"pts_ever_severe_dayn14ton1"]
junk[,"pts_never_severe_day0to29"]=junk[,"pts_all_day0to29"]-junk[,"pts_ever_severe_day0to29"]
junk[,"pts_never_severe_day30to89"]=junk[,"pts_all_day30to89"]-junk[,"pts_ever_severe_day30to89"]
junk[,"pts_never_severe_day30plus"]=junk[,"pts_all_day30plus"]-junk[,"pts_ever_severe_day30plus"]
junk[,"pts_never_severe_day90plus"]=junk[,"pts_all_day90plus"]-junk[,"pts_ever_severe_day90plus"]
junk[,"pts_never_severe_1st_day0to29"]=junk[,"pts_all_1st_day0to29"]-junk[,"pts_ever_severe_1st_day0to29"]
junk[,"pts_never_severe_1st_day30plus"]=junk[,"pts_all_1st_day30plus"]-junk[,"pts_ever_severe_1st_day30plus"]
junk[,"pts_never_severe_1st_day90plus"]=junk[,"pts_all_1st_day90plus"]-junk[,"pts_ever_severe_1st_day90plus"]
junk[,"pts_all_1st_day30to89"]=junk[,"pts_all_1st_day30plus"]-junk[,"pts_all_1st_day90plus"]
junk[,"pts_ever_severe_1st_day30to89"]=junk[,"pts_ever_severe_1st_day30plus"]-junk[,"pts_ever_severe_1st_day90plus"]
for(ll in 25:36){
junk[which(junk[,ll]<0),ll]=NA
}
junk[,"pts_never_severe_1st_day30to89"]=junk[,"pts_all_1st_day30to89"]-junk[,"pts_ever_severe_1st_day30to89"]
junk[which(junk[,"pts_never_severe_1st_day30to89"]<0),"pts_never_severe_1st_day30to89"]=NA
diagnosis=rbind(diagnosis,junk)
}
saveRDS(diagnosis,paste0(dir.output,"diag_proc_med.RDS"))
tmp=files[grep("RaceBy4CECode", files, value=FALSE)]
race.4ce=NULL
for(p in 1:length(tmp)){
junk=read.csv(tmp[p]);colnames(junk)=tolower(colnames(junk))
for(ll in c(4,5)){
junk[which(junk[,ll]%in%c(-99,NA,Inf,-999)),ll]=NA
}
junk[,"pts_never_severe"]=junk[,"pts_all"]-junk[,"pts_ever_severe"]
junk[which(junk[,"pts_never_severe"]<0),"pts_never_severe"]=NA
race.4ce=rbind(race.4ce,junk)
}
saveRDS(race.4ce,paste0(dir.output,"race_4ce.RDS"))
#===============================================================================================================================