#Problem 1: Patient Registry

patient_registry<-c("Rahim","Karim","Sultana")
patient_registry
## [1] "Rahim"   "Karim"   "Sultana"
patient_registry[2]
## [1] "Karim"

#Problem 2: Blood Pressure Data

SBP_HTN_patient<-c(145, 160, 138, 152)
SBP_HTN_patient[c(3,4)]
## [1] 138 152

#Problem 3: Gene Expression Counts

Expression_count_TP53<-c(500,800, 450, 600)
mean(Expression_count_TP53)
## [1] 587.5

#problem 4: Small Cohort Data Frame

nutrational_study<-data.frame(Name=c("Ali","Sonia","Kabir"),
Age=c(35,29,41),BMI=c(24.5,28.2,31.0))
nutrational_study
##    Name Age  BMI
## 1   Ali  35 24.5
## 2 Sonia  29 28.2
## 3 Kabir  41 31.0

Problem 5: Add BMI Classification

nutrational_study$BMI_classification<-ifelse(nutrational_study$BMI<25,"Normal",ifelse(nutrational_study$BMI<30,"Overweight","Obese"))
nutrational_study
##    Name Age  BMI BMI_classification
## 1   Ali  35 24.5             Normal
## 2 Sonia  29 28.2         Overweight
## 3 Kabir  41 31.0              Obese

#Problem 6: Subset Patients by Age

older_patients<-nutrational_study[nutrational_study$Age>30,]
older_patients
##    Name Age  BMI BMI_classification
## 1   Ali  35 24.5             Normal
## 3 Kabir  41 31.0              Obese

#Problem 7:Subset Patients by BMI

Obese_patient<-nutrational_study[nutrational_study$BMI_classification=="Obese",]
Obese_patient
##    Name Age BMI BMI_classification
## 3 Kabir  41  31              Obese

#Problem 8: Create a Gene Expression Matrix

BRCA1<-c(120,150,130)
EGFR<-c(300,350,400)
MYC<-c(800,900,950)
patient_name<-c("P1","P2","P3")
Gene_Expression<-matrix(data=c(BRCA1,EGFR,MYC),nrow=3,ncol=3,byrow=TRUE)
Gene_Expression
##      [,1] [,2] [,3]
## [1,]  120  150  130
## [2,]  300  350  400
## [3,]  800  900  950
rownames(Gene_Expression)<-c("BRCA1","EGFR","MYC")
colnames(Gene_Expression)<-patient_name
Gene_Expression
##        P1  P2  P3
## BRCA1 120 150 130
## EGFR  300 350 400
## MYC   800 900 950

#Problem 9: Extract Specific Expression Value

MYCs_expression_Patient_2<-Gene_Expression[3,2]
MYCs_expression_Patient_2
## [1] 900

#Problem 10: Create a Multi-Object List

patient_age<-c(35,29,41)
BRCA1<-c(120,150,130)
EGFR<-c(300,350,400)
MYC<-c(800,900,950)
patient_name<-c("P1","P2","P3")
Gene_Expression<-matrix(data=c(BRCA1,EGFR,MYC),nrow=3,ncol=3,byrow=TRUE)
Gene_Expression
##      [,1] [,2] [,3]
## [1,]  120  150  130
## [2,]  300  350  400
## [3,]  800  900  950
rownames(Gene_Expression)<-c("BRCA1","EGFR","MYC")
colnames(Gene_Expression)<-patient_name
Gene_Expression
##        P1  P2  P3
## BRCA1 120 150 130
## EGFR  300 350 400
## MYC   800 900 950
nutrational_study<-data.frame(Name=c("Ali","Sonia","Kabir"),
Age=c(35,29,41),BMI=c(24.5,28.2,31.0))
nutrational_study
##    Name Age  BMI
## 1   Ali  35 24.5
## 2 Sonia  29 28.2
## 3 Kabir  41 31.0
study_list<-list(patient_age,Gene_Expression,nutrational_study)
study_list
## [[1]]
## [1] 35 29 41
## 
## [[2]]
##        P1  P2  P3
## BRCA1 120 150 130
## EGFR  300 350 400
## MYC   800 900 950
## 
## [[3]]
##    Name Age  BMI
## 1   Ali  35 24.5
## 2 Sonia  29 28.2
## 3 Kabir  41 31.0

#Problem 11: Extract from a List

only_EGFR_expression<-study_list[[2]][2,]
only_EGFR_expression
##  P1  P2  P3 
## 300 350 400

#Problem 12: Conditional Statement for Glucose Check

x<-c(100,110,125)
FBG_pt1<-ifelse(x<100,"normal",ifelse(x<125,"prediabetes","diabetes"))
FBG_pt1
## [1] "prediabetes" "prediabetes" "diabetes"

#Problem 13: Identify High-Risk Patients

Patients<-data.frame(name=c("Tania","Mahir","Jui","Imran"),Age=c(42,37,45,50), BMI=c(31.5,28.0,29.5,32.0))
high_risk<-Patients[Patients$Age>40 & Patients$BMI>=30,]
high_risk
##    name Age  BMI
## 1 Tania  42 31.5
## 4 Imran  50 32.0

#Problem 14: Integrate Biomedical Data in a List

pt_name<-c("a","b","c")
pt_age<-c(25,27,29)
pt_sex<-c("male","male","female")
patient_details<-c(pt_name,pt_age,pt_sex)

tumor_markers<-matrix(10:18,nrow=3,ncol=3,byrow=TRUE)
colnames(tumor_markers)<-c("CA125","CEA","PSA")
rownames(tumor_markers)<-c(pt_name)
tumor_markers
##   CA125 CEA PSA
## a    10  11  12
## b    13  14  15
## c    16  17  18
survival_times<-c(2,4,6)
Biomedical_data<-list(patient_details,tumor_markers,survival_times)
Biomedical_data
## [[1]]
## [1] "a"      "b"      "c"      "25"     "27"     "29"     "male"   "male"  
## [9] "female"
## 
## [[2]]
##   CA125 CEA PSA
## a    10  11  12
## b    13  14  15
## c    16  17  18
## 
## [[3]]
## [1] 2 4 6
CEA_2nd_pt<-Biomedical_data[[2]]["b","CEA"]
CEA_2nd_pt
## [1] 14
survival_3rd_pt<-Biomedical_data[[3]][3]
survival_3rd_pt
## [1] 6

#Problem 15: Automated Classification of Anemia Status

pt_name<-c("q","w","e","r","t","y")
hb_values<-c(11.2, 13.5, 9.8,14.1, 12.0, 8.7)
pt_details<-data.frame(pt_name,hb_values)
pt_details
##   pt_name hb_values
## 1       q      11.2
## 2       w      13.5
## 3       e       9.8
## 4       r      14.1
## 5       t      12.0
## 6       y       8.7
pt_details$Anemia_status<-ifelse(pt_details$hb_values<12,"Anemia","Normal")
pt_details
##   pt_name hb_values Anemia_status
## 1       q      11.2        Anemia
## 2       w      13.5        Normal
## 3       e       9.8        Anemia
## 4       r      14.1        Normal
## 5       t      12.0        Normal
## 6       y       8.7        Anemia