#Problem 1: Evaluate Glucose Level

patient_fbg<- 112
glucose_value<-if(patient_fbg<100){
  print("normal")
}else if(patient_fbg<=125){
  print("Prediabetes")
}else{
    print("diabetes")
  }                      
## [1] "Prediabetes"

#Problem 2: Check for Fever

patient_temp<-38.2
status<-if(patient_temp>37.5){print("fever detected")
}else{print("Normal")}
## [1] "fever detected"

#problem3:Problem 3: BMI Classification

participant_BMI<-29.5
BMI_status<-if(participant_BMI<29.5){print("Normal")
  }else{print("overweight")}
## [1] "overweight"

#Problem 4: Lab Result Flagging

patient_hb_level<-10.5
lab_result<-if(patient_hb_level<12){print("anemia")
  }else{print("normal")}
## [1] "anemia"

#Problem 5: Evaluate Cholesterol Panel

patient_LDL<-165
cholesterol_panel<-if(patient_LDL<130){print("optimal")
}else if(patient_LDL>130 & patient_LDL<160){print("Borderline")
}else{print("high")}
## [1] "high"

#Problem 6: Create a Clinical Dataset

names<-c("Aisha","Rahman","Rima","Hossain")
age<-c(45,52,37,60)
BMI<-c(31.2,28.5,24.1,33.4)
Bp_systolic<-c(150,165,120,175)
patients<-data.frame(names,age,BMI,Bp_systolic)
patients
##     names age  BMI Bp_systolic
## 1   Aisha  45 31.2         150
## 2  Rahman  52 28.5         165
## 3    Rima  37 24.1         120
## 4 Hossain  60 33.4         175

#7Problem 7: Add a Hypertension Column

names<-c("Aisha","Rahman","Rima","Hossain")
age<-c(45,52,37,60)
BMI<-c(31.2,28.5,24.1,33.4)
Bp_systolic<-c(150,165,120,175)
patients<-data.frame(names,age,BMI,Bp_systolic)
patients
##     names age  BMI Bp_systolic
## 1   Aisha  45 31.2         150
## 2  Rahman  52 28.5         165
## 3    Rima  37 24.1         120
## 4 Hossain  60 33.4         175
patients$hypertensive<-ifelse((Bp_systolic>=140),"yes","no")
patients
##     names age  BMI Bp_systolic hypertensive
## 1   Aisha  45 31.2         150          yes
## 2  Rahman  52 28.5         165          yes
## 3    Rima  37 24.1         120           no
## 4 Hossain  60 33.4         175          yes

#Problem 8: Add an Obesity Status Column

names<-c("Aisha","Rahman","Rima","Hossain")
age<-c(45,52,37,60)
BMI<-c(31.2,28.5,24.1,33.4)
Bp_systolic<-c(150,165,120,175)
patients<-data.frame(names,age,BMI,Bp_systolic)
patients
##     names age  BMI Bp_systolic
## 1   Aisha  45 31.2         150
## 2  Rahman  52 28.5         165
## 3    Rima  37 24.1         120
## 4 Hossain  60 33.4         175
patients$BMI_Status<-ifelse(BMI<25,"normal",
ifelse(BMI>=30,
  "obese",
  "overwight")
)
patients
##     names age  BMI Bp_systolic BMI_Status
## 1   Aisha  45 31.2         150      obese
## 2  Rahman  52 28.5         165  overwight
## 3    Rima  37 24.1         120     normal
## 4 Hossain  60 33.4         175      obese

#Problem 9: Identify Elderly Patients

names<-c("Aisha","Rahman","Rima","Hossain")
age<-c(45,52,37,60)
BMI<-c(31.2,28.5,24.1,33.4)
Bp_systolic<-c(150,165,120,175)
patients<-data.frame(names,age,BMI,Bp_systolic)
patients
##     names age  BMI Bp_systolic
## 1   Aisha  45 31.2         150
## 2  Rahman  52 28.5         165
## 3    Rima  37 24.1         120
## 4 Hossain  60 33.4         175
eldery_geriatric_trial<-patients[patients$age>=50,]
eldery_geriatric_trial
##     names age  BMI Bp_systolic
## 2  Rahman  52 28.5         165
## 4 Hossain  60 33.4         175

#Problem 10: Assign Risk Level

names<-c("Aisha","Rahman","Rima","Hossain")
age<-c(45,52,37,60)
BMI<-c(31.2,28.5,24.1,33.4)
Bp_systolic<-c(150,165,120,175)
patients<-data.frame(names,age,BMI,Bp_systolic)
patients
##     names age  BMI Bp_systolic
## 1   Aisha  45 31.2         150
## 2  Rahman  52 28.5         165
## 3    Rima  37 24.1         120
## 4 Hossain  60 33.4         175
patients$hypertensive<-ifelse((Bp_systolic>=140),"yes","no")
ifelse(BMI>=30,
  "obese",
  "overwight")
## [1] "obese"     "overwight" "overwight" "obese"
eldery_geriatric_trial<-patients[patients$age>=50,]
patients
##     names age  BMI Bp_systolic hypertensive
## 1   Aisha  45 31.2         150          yes
## 2  Rahman  52 28.5         165          yes
## 3    Rima  37 24.1         120           no
## 4 Hossain  60 33.4         175          yes
patients$risk_level<-ifelse(age>50 & patients$hypertensive=="yes","high risk",
ifelse((age>50 & patients$hypertensive=="no")|(age<=50 & patients$hypertensive=="yes"),"moderate risk","low risk"))
patients
##     names age  BMI Bp_systolic hypertensive    risk_level
## 1   Aisha  45 31.2         150          yes moderate risk
## 2  Rahman  52 28.5         165          yes     high risk
## 3    Rima  37 24.1         120           no      low risk
## 4 Hossain  60 33.4         175          yes     high risk

#Section C – Loops and Iteration

x<-c(1,2,3,4,5,6,7)
for(x in 1:7){
print(paste("please upload the lab data for day",x))
}
## [1] "please upload the lab data for day 1"
## [1] "please upload the lab data for day 2"
## [1] "please upload the lab data for day 3"
## [1] "please upload the lab data for day 4"
## [1] "please upload the lab data for day 5"
## [1] "please upload the lab data for day 6"
## [1] "please upload the lab data for day 7"

#Problem 12: Sequential Year Tracker

years<-(2015:2025)
for(years in 2015:2025){
print(paste("processing year:",years))
}
## [1] "processing year: 2015"
## [1] "processing year: 2016"
## [1] "processing year: 2017"
## [1] "processing year: 2018"
## [1] "processing year: 2019"
## [1] "processing year: 2020"
## [1] "processing year: 2021"
## [1] "processing year: 2022"
## [1] "processing year: 2023"
## [1] "processing year: 2024"
## [1] "processing year: 2025"

#Problem 13: Viral Load Tracking

 viral_loads<-c(100, 550, 1200, 20000, 850)
for (viral_load in viral_loads)
{if(viral_load<1000){print("normal")
}else if (viral_load<10000){
  print("Elevated")
}else{
  print("critical")
}
}
## [1] "normal"
## [1] "normal"
## [1] "Elevated"
## [1] "critical"
## [1] "normal"

#Problem 14: Automated Clinical Categorization

name<-c("Rahim","Sumaiya","Babul","Joya")
CD4_Count<-c(120,480,230,700)
HIV_patients<-data.frame(name,CD4_Count)
HIV_patients
##      name CD4_Count
## 1   Rahim       120
## 2 Sumaiya       480
## 3   Babul       230
## 4    Joya       700
HIV_patients$Immunity_Status<-ifelse(HIV_patients$CD4_Count<200,"severe",ifelse(HIV_patients$CD4_Count>500,"Normal","Moderate"))
HIV_patients
##      name CD4_Count Immunity_Status
## 1   Rahim       120          severe
## 2 Sumaiya       480        Moderate
## 3   Babul       230        Moderate
## 4    Joya       700          Normal

#Problem 15: Integrating Loops and Conditionals for Clinical Scoring

Infection_score<-c(10,35,50,80,95)
severity<-c()
for (score in Infection_score){
if (score<30){
severity<-c(severity,"Mild")
} else if (score<70){
severity<-c(severity,"Moderate")
}else{severity<-c(severity,"Severe")
}
}
severity
## [1] "Mild"     "Moderate" "Moderate" "Severe"   "Severe"
Severity_label<-c("Mild","Moderate","Moderate","Severe","Severe")
clinical_score<-data.frame(Infection_score,Severity_label)
clinical_score
##   Infection_score Severity_label
## 1              10           Mild
## 2              35       Moderate
## 3              50       Moderate
## 4              80         Severe
## 5              95         Severe

#Problem 16: Combine All Skills – Hospital Ward Analysis

Name <- c("Mina", "Rafi", "Sima", "Rony", "Asha", "Nayeem")
Age <- c(25, 50, 61, 45, 70, 58)
Temp <- c(36.8, 38.5, 39.2, 37.0, 38.0, 36.5)
SpO2 <- c(99, 95, 91, 98, 89, 97)

hospital_ward <- data.frame(Name, Age, Temp, SpO2)

Condition <- c()

for (i in 1:nrow(hospital_ward)) {

  if (hospital_ward$Temp[i] > 38 & hospital_ward$SpO2[i] < 94) {

    Condition <- c(Condition, "Critical")

  } else if (hospital_ward$Temp[i] > 37 & hospital_ward$SpO2[i] < 96) {

    Condition <- c(Condition, "At Risk")

  } else {

    Condition <- c(Condition, "Stable")
  }
}

hospital_ward$Condition <- Condition

hospital_ward
##     Name Age Temp SpO2 Condition
## 1   Mina  25 36.8   99    Stable
## 2   Rafi  50 38.5   95   At Risk
## 3   Sima  61 39.2   91  Critical
## 4   Rony  45 37.0   98    Stable
## 5   Asha  70 38.0   89   At Risk
## 6 Nayeem  58 36.5   97    Stable