# patients.R Sript that manages patient pressure
#(a) Building the 5 × 3 matrix
patients <- matrix(
c(80, 120, 98.6,
75, 110, 99.1,
90, 130, 98.4,
70, 115, 98.7,
85, 125, 99.0),
nrow = 5,
byrow = TRUE
)
#(b) Displaying the raw matrix
print("Raw matrix:")
## [1] "Raw matrix:"
print(patients)
## [,1] [,2] [,3]
## [1,] 80 120 98.6
## [2,] 75 110 99.1
## [3,] 90 130 98.4
## [4,] 70 115 98.7
## [5,] 85 125 99.0
#(c) Add row & column labels
colnames(patients) <- c("HeartRate", "SystolicBp", "Temperature")
rownames(patients) <- sprintf("%03d", 1:5) # 001, 002, …, 005
cat("\nFormatted matrix:\n")
##
## Formatted matrix:
print(patients)
## HeartRate SystolicBp Temperature
## 001 80 120 98.6
## 002 75 110 99.1
## 003 90 130 98.4
## 004 70 115 98.7
## 005 85 125 99.0
#(d) Mean heart rate
mean_hr <- mean(patients[, "HeartRate"])
cat("\nMean heart rate:", round(mean_hr, 2), "\n")
##
## Mean heart rate: 80
#(e) Filtering heart rate > 75
high_hr_patients <- patients[patients[, "HeartRate"] > 75, ]
cat("\nPatients with heart rate > 75:\n")
##
## Patients with heart rate > 75:
print(high_hr_patients)
## HeartRate SystolicBp Temperature
## 001 80 120 98.6
## 003 90 130 98.4
## 005 85 125 99.0
#(f) Scatter plot: HeartRate vs SystolicBp
plot(patients[, "HeartRate"],
patients[, "SystolicBp"],
xlab = "Heart Rate",
ylab = "Systolic Blood Pressure",
main = "Scatter Plot: Heart Rate vs Systolic BP",
pch = 19,
col = "steelblue")
