#Problem 1: Identifying Patients with Abnormal Glucose Patterns

patients<-c("P1","P2","P3","P4","p5")
conditions<-c("Fasting_glucose","pp_1h","pp_2h")
Fasting_glucose <-c(95,110,85,98,102)
pp_1h<-c(160,190,150,200,175)
pp_2h<-c(120,170,130,180,150)
patient_matrix<-matrix(c(Fasting_glucose,pp_1h,pp_2h),nrow=5,ncol=3)
rownames(patient_matrix)<-patients
colnames(patient_matrix)<-conditions
patient_matrix
##    Fasting_glucose pp_1h pp_2h
## P1              95   160   120
## P2             110   190   170
## P3              85   150   130
## P4              98   200   180
## p5             102   175   150
abnormal_glucose<-ifelse(Fasting_glucose>=100|pp_1h>=180|pp_2h>=140,
"Abnormal","Normal")
abnormal_glucose
## [1] "Normal"   "Abnormal" "Normal"   "Abnormal" "Abnormal"
patients_with_abnormal_glucose<-patient_matrix[abnormal_glucose=="Abnormal",]
patients_with_abnormal_glucose
##    Fasting_glucose pp_1h pp_2h
## P2             110   190   170
## P4              98   200   180
## p5             102   175   150

#Problem 2: Differential Gene Expression Analysis

pilot_study<-data.frame(gene=c("TP53","BRCA1","MYC","EGFR","ACTB"),healthy=c(250,120,500,300,1000),Tumor=c(800,130,2000,900,1000))
pilot_study
##    gene healthy Tumor
## 1  TP53     250   800
## 2 BRCA1     120   130
## 3   MYC     500  2000
## 4  EGFR     300   900
## 5  ACTB    1000  1000
pilot_study$fold_change<-pilot_study$Tumor/pilot_study$healthy
pilot_study
##    gene healthy Tumor fold_change
## 1  TP53     250   800    3.200000
## 2 BRCA1     120   130    1.083333
## 3   MYC     500  2000    4.000000
## 4  EGFR     300   900    3.000000
## 5  ACTB    1000  1000    1.000000
pilot_study$status<-ifelse(pilot_study$fold_change>=2,"Upregulated",ifelse(pilot_study$fold_change<=0.5,"Downregulated","No change"))
pilot_study
##    gene healthy Tumor fold_change      status
## 1  TP53     250   800    3.200000 Upregulated
## 2 BRCA1     120   130    1.083333   No change
## 3   MYC     500  2000    4.000000 Upregulated
## 4  EGFR     300   900    3.000000 Upregulated
## 5  ACTB    1000  1000    1.000000   No change
pilot_study[pilot_study$status=="Upregulated",]
##   gene healthy Tumor fold_change      status
## 1 TP53     250   800         3.2 Upregulated
## 3  MYC     500  2000         4.0 Upregulated
## 4 EGFR     300   900         3.0 Upregulated

#Problem 3: Clinical Trial Stratification

drug_trial<-data.frame(ID=c("p1","p2","p3","p4","p5","p6","p7","p8"),Age=c(45,50,39,60,55,42,48,52),Baseline_Bp=c(160,150,145,170,160,135,155,162),Post_Bp=c(140,135,142,155,150,130,138,145))
drug_trial
##   ID Age Baseline_Bp Post_Bp
## 1 p1  45         160     140
## 2 p2  50         150     135
## 3 p3  39         145     142
## 4 p4  60         170     155
## 5 p5  55         160     150
## 6 p6  42         135     130
## 7 p7  48         155     138
## 8 p8  52         162     145
drug_trial$Response<-ifelse(drug_trial$Baseline_Bp-drug_trial$Post_Bp>=15,"Responder","Non_responder")
drug_trial
##   ID Age Baseline_Bp Post_Bp      Response
## 1 p1  45         160     140     Responder
## 2 p2  50         150     135     Responder
## 3 p3  39         145     142 Non_responder
## 4 p4  60         170     155     Responder
## 5 p5  55         160     150 Non_responder
## 6 p6  42         135     130 Non_responder
## 7 p7  48         155     138     Responder
## 8 p8  52         162     145     Responder
drug_trial_responder<-drug_trial[drug_trial$Age>50 &drug_trial$Response=="Responder",]
drug_trial_responder
##   ID Age Baseline_Bp Post_Bp  Response
## 4 p4  60         170     155 Responder
## 8 p8  52         162     145 Responder