# ============================================================================
# HW1 R INTRO EXERCISE- PATIENTS DATASET
# Biostats 2026 - Introduction to R Programming
# Name: ________Liliana Vega________    
# Date: _______6.8.26_________
# ============================================================================

# 
# Instructions:
# - Complete all exercises below
# - Test your code by running it line by line
# - Compile your report
# - Submit your html report with all answers
# - Use the provided dataset: patients.csv
# ============================================================================

# EXERCISE 1: LOAD THE DATA
# ============================================================================
# Load the patients.csv file and store it in a variable called patients
patients<-read.csv("C:/Users/liliv/Downloads/patients.csv")
# TODO: use read.csv() to load "patients.csv"


# EXERCISE 2: NUMBER OF OBSERVATIONS/RECORDS
# ============================================================================
# How many observations (rows) are in the patients dataset?

 # TODO: use nrow() or dim() to find the number of rows
dim(patients)
## [1] 25  8
# EXERCISE 3: NUMBER OF VARIABLES
# ============================================================================
# How many variables (columns) are in the patients dataset?

# TODO: use ncol() or dim() to find the number of columns
ncol(patients)
## [1] 8
# EXERCISE 4: IDENTIFY CONTINUOUS VARIABLES
# ============================================================================
# Continuous variables are numeric measurements that can take many values.
# Examples: Age, Cholesterol, BMI, Blood Pressure
#
# List all the continuous variables in the patients dataset:

# TODO: List the continuous variable names as a character vector
# Hint: You might need to use names() and/or view the data with head()
names(patients)
## [1] "PatientID"   "Age"         "Gender"      "SystolicBP"  "DiastolicBP"
## [6] "Cholesterol" "BMI"         "Smoker"
head(patients)
##   PatientID Age Gender SystolicBP DiastolicBP Cholesterol  BMI Smoker
## 1         1  45      M        125          78         210 24.5      0
## 2         2  52      F        142          88         245 26.8      1
## 3         3  38      M        118          75         195 23.2      0
## 4         4  61      F        148          92         268 28.1      1
## 5         5  42      M        130          82         220 25.1      0
## 6         6  55      F        138          85         235 27.3      0
# EXERCISE 5: IDENTIFY BINARY VARIABLES
# ============================================================================
# Binary variables are categorical with exactly 2 possible values (e.g., Yes/No, 0/1, M/F).
#
# List all the binary variables in the patients dataset:

# TODO: List the binary variable names as a character vector

# ============================================================================
# OPTIONAL: explore your dataset
# ============================================================================
# Uncomment and run the commands below 

# View the first 6 rows:
head(patients)
##   PatientID Age Gender SystolicBP DiastolicBP Cholesterol  BMI Smoker
## 1         1  45      M        125          78         210 24.5      0
## 2         2  52      F        142          88         245 26.8      1
## 3         3  38      M        118          75         195 23.2      0
## 4         4  61      F        148          92         268 28.1      1
## 5         5  42      M        130          82         220 25.1      0
## 6         6  55      F        138          85         235 27.3      0
# Get the structure and data types:
str(patients)
## 'data.frame':    25 obs. of  8 variables:
##  $ PatientID  : int  1 2 3 4 5 6 7 8 9 10 ...
##  $ Age        : int  45 52 38 61 42 55 48 35 59 41 ...
##  $ Gender     : chr  "M" "F" "M" "F" ...
##  $ SystolicBP : int  125 142 118 148 130 138 145 115 152 128 ...
##  $ DiastolicBP: int  78 88 75 92 82 85 90 72 95 80 ...
##  $ Cholesterol: int  210 245 195 268 220 235 255 188 278 205 ...
##  $ BMI        : num  24.5 26.8 23.2 28.1 25.1 27.3 26.9 22.8 29.2 24.6 ...
##  $ Smoker     : int  0 1 0 1 0 0 1 0 1 0 ...
# Get summary statistics:
summary(patients)
##    PatientID       Age              Gender     SystolicBP     DiastolicBP  
##  Min.   : 1   Min.   :35.00   Length   :25   Min.   :115.0   Min.   :71.0  
##  1st Qu.: 7   1st Qu.:41.00   N.unique : 2   1st Qu.:124.0   1st Qu.:78.0  
##  Median :13   Median :48.00   N.blank  : 0   Median :135.0   Median :85.0  
##  Mean   :13   Mean   :47.84   Min.nchar: 1   Mean   :134.2   Mean   :83.8  
##  3rd Qu.:19   3rd Qu.:55.00   Max.nchar: 1   3rd Qu.:145.0   3rd Qu.:90.0  
##  Max.   :25   Max.   :61.00                  Max.   :155.0   Max.   :97.0  
##   Cholesterol       BMI            Smoker   
##  Min.   :185   Min.   :22.50   Min.   :0.0  
##  1st Qu.:205   1st Qu.:24.10   1st Qu.:0.0  
##  Median :228   Median :26.20   Median :0.0  
##  Mean   :230   Mean   :25.87   Mean   :0.4  
##  3rd Qu.:255   3rd Qu.:27.30   3rd Qu.:1.0  
##  Max.   :285   Max.   :29.80   Max.   :1.0
# Get column names:
names(patients)
## [1] "PatientID"   "Age"         "Gender"      "SystolicBP"  "DiastolicBP"
## [6] "Cholesterol" "BMI"         "Smoker"