This report presents the categorization of blood pressure readings, detection of hypertensive crisis, and generation of personalized health messages for each client. The dataset includes clients’ demographic details and clinical measurements such as systolic and diastolic blood pressure and protein in urine.
# Create the dataset
bp <- data.frame(
Name = c("Alice","Selina","Rose","Hibiscus","Sunflower","Tolu","Mary","Lola","Sandra","Margaret", "Celine","Colem"),
Age = c(25, 30, 35, 45, 19, 22, 45, 34, 23, 26, 33, 32),
Sysolic = c(126, 167, 170, 230, 102, 134, 155, 254, 112, 130, 144, 150),
Diastolic = c(76, 110, 120, 91, 76, 69, 102, 189, 64, 78, 89, 103),
Protein_in_urine = c("NO", "YES", "YES", "YES", "NO", "NO", "NO", "YES", "YES", "NO","YES","YES")
)Blood pressure categories were defined based on standard clinical thresholds.
# Categorize hypertension stages
bp$Hypertension_Stage <- ifelse(bp$Sysolic < 120 & bp$Diastolic < 80, "Normal",
ifelse(bp$Sysolic >= 120 & bp$Sysolic <= 129 & bp$Diastolic < 80, "Elevated",
ifelse((bp$Sysolic >= 130 & bp$Sysolic <= 139) |
(bp$Diastolic >= 80 & bp$Diastolic <= 89),
"Stage 1 Hypertension",
"Stage 2 Hypertension")))
# Styled table
bp %>%
select(Name, Sysolic, Diastolic, Hypertension_Stage) %>%
kable("html", caption = "Blood Pressure Categorization") %>%
kable_styling(full_width = FALSE, bootstrap_options = c("striped", "hover", "condensed", "responsive"))| Name | Sysolic | Diastolic | Hypertension_Stage |
|---|---|---|---|
| Alice | 126 | 76 | Elevated |
| Selina | 167 | 110 | Stage 2 Hypertension |
| Rose | 170 | 120 | Stage 2 Hypertension |
| Hibiscus | 230 | 91 | Stage 2 Hypertension |
| Sunflower | 102 | 76 | Normal |
| Tolu | 134 | 69 | Stage 1 Hypertension |
| Mary | 155 | 102 | Stage 2 Hypertension |
| Lola | 254 | 189 | Stage 2 Hypertension |
| Sandra | 112 | 64 | Normal |
| Margaret | 130 | 78 | Stage 1 Hypertension |
| Celine | 144 | 89 | Stage 1 Hypertension |
| Colem | 150 | 103 | Stage 2 Hypertension |
Hypertensive crisis is defined as systolic ≥ 180 mmHg or diastolic ≥ 120 mmHg.
bp$Hypertensive_Crisis <- ifelse(bp$Sysolic >= 180 | bp$Diastolic >= 120, "YES", "NO")
# Styled table
bp %>%
select(Name, Sysolic, Diastolic, Hypertensive_Crisis) %>%
kable("html", caption = "Hypertensive Crisis Detection") %>%
kable_styling(full_width = FALSE, bootstrap_options = c("striped", "hover", "condensed", "responsive"))| Name | Sysolic | Diastolic | Hypertensive_Crisis |
|---|---|---|---|
| Alice | 126 | 76 | NO |
| Selina | 167 | 110 | NO |
| Rose | 170 | 120 | YES |
| Hibiscus | 230 | 91 | YES |
| Sunflower | 102 | 76 | NO |
| Tolu | 134 | 69 | NO |
| Mary | 155 | 102 | NO |
| Lola | 254 | 189 | YES |
| Sandra | 112 | 64 | NO |
| Margaret | 130 | 78 | NO |
| Celine | 144 | 89 | NO |
| Colem | 150 | 103 | NO |
The following section provides customized health messages for each client, based on their blood pressure readings.
# Loop through each row in the dataset and create personalized messages
for (i in 1:nrow(bp)) {
if (bp$Sysolic[i] >= 140 | bp$Diastolic[i] >= 90) {
print(paste(bp$Name[i], "has high blood pressure. Please consult a doctor!"))
} else if (bp$Sysolic[i] >= 120) {
print(paste(bp$Name[i], "has elevated blood pressure. Monitor closely and adopt a healthy lifestyle."))
} else {
print(paste(bp$Name[i], "has normal blood pressure. Keep up the good habits!"))
}
}## [1] "Alice has elevated blood pressure. Monitor closely and adopt a healthy lifestyle."
## [1] "Selina has high blood pressure. Please consult a doctor!"
## [1] "Rose has high blood pressure. Please consult a doctor!"
## [1] "Hibiscus has high blood pressure. Please consult a doctor!"
## [1] "Sunflower has normal blood pressure. Keep up the good habits!"
## [1] "Tolu has elevated blood pressure. Monitor closely and adopt a healthy lifestyle."
## [1] "Mary has high blood pressure. Please consult a doctor!"
## [1] "Lola has high blood pressure. Please consult a doctor!"
## [1] "Sandra has normal blood pressure. Keep up the good habits!"
## [1] "Margaret has elevated blood pressure. Monitor closely and adopt a healthy lifestyle."
## [1] "Celine has high blood pressure. Please consult a doctor!"
## [1] "Colem has high blood pressure. Please consult a doctor!"
This analysis categorized clients’ blood pressure levels into Normal, Elevated, Stage 1 Hypertension, and Stage 2 Hypertension, and further identified individuals experiencing a hypertensive crisis. Finally, personalized health advice was generated for each client, ensuring that recommendations are clear, visually highlighted, and tailored to their condition.