#Problem 1: Recording Volunteer Names

volunteer_names<-c("Hashem", "Haris", "Mostafa")
volunteer_names[1]
## [1] "Hashem"

#Problem 2: Assigning Patient IDs

Patient_IDs<-c(1,2,3,4)
Patient_IDs
## [1] 1 2 3 4

#Problem 3: Student Participants in a Workshop

medical_students<-c("maria","Shirmin","Alam")
class(medical_students)
## [1] "character"

#Problem 4: Extracting Test Results

Blood_Pressure_reading<-c(120,132,138)
Blood_Pressure_reading[c(2,3)]
## [1] 132 138

#Problem 5: Labeling Gene Expression

cancer_related_genes<-c(230,120,450)
names(cancer_related_genes)<-c("TP53","BRCA1","MYC")
cancer_related_genes["BRCA1"]
## BRCA1 
##   120

#Problem 6: Creating an Expression Matrix

expression_matrix<-matrix(c(1:12),nrow=4,ncol=3,byrow=TRUE)
expression_matrix
##      [,1] [,2] [,3]
## [1,]    1    2    3
## [2,]    4    5    6
## [3,]    7    8    9
## [4,]   10   11   12

#Problem 7: Checking Data Structure

class(expression_matrix)
## [1] "matrix" "array"

#Problem 8: Mixing Data Types

new_matrix<-matrix(c(1,2,3,"hello", "hi", "bye"), nrow=2, ncol=3)
new_matrix
##      [,1] [,2]    [,3] 
## [1,] "1"  "3"     "hi" 
## [2,] "2"  "hello" "bye"

#Problem 9: Combining Patient Results into a Matrix

Asif<-c(90, 160, 120)
Harun<-c(100, 180, 150)
Afridi<-c(80, 145, 110)

Patient_matrix<-matrix(c(Asif,Harun,Afridi),nrow=3,ncol=3,byrow=TRUE)
rownames(Patient_matrix)<-c("ASIF","HARUN","AFRIDI")
Patient_matrix
##        [,1] [,2] [,3]
## ASIF     90  160  120
## HARUN   100  180  150
## AFRIDI   80  145  110

#Problem 10: Adding Column Names for Time Points

Patient_matrix<-matrix(c(Asif,Harun,Afridi),nrow=3,ncol=3,byrow=TRUE)
rownames(Patient_matrix)<-c("ASIF","HARUN","AFRIDI")
colnames(Patient_matrix)<-c("Baseline","Treatment1", "Treatment2")
Patient_matrix
##        Baseline Treatment1 Treatment2
## ASIF         90        160        120
## HARUN       100        180        150
## AFRIDI       80        145        110

#Problem 11: Adding Row Names for Patients #solved in problem 9

#Problem 12: Extracting a Specific Value

Patient_matrix["ASIF","Treatment2"]
## [1] 120

#Problem 13: Comparing Two Patients

New_Patient_matrix<-Patient_matrix[c(1,3),c(1,3)]
rownames(New_Patient_matrix)<-c("ASIF","AFRIDI")
New_Patient_matrix
##        Baseline Treatment2
## ASIF         90        120
## AFRIDI       80        110

#Problem 14: Extracting Row Subsets

Haruns_glucose_level<-Patient_matrix["HARUN",c(1,2)]
Haruns_glucose_level
##   Baseline Treatment1 
##        100        180

#Problem 15:NA

#Problem 16: Building a Patient Data Frame

Name<-c("Tamim","Imrul","Fiz")
Age<-c(35,39,37)
Number_of_mutations_detected<-c(4,1,0)
Married<-c(TRUE,TRUE,TRUE)
data_frame<-data.frame(Name,Age,Number_of_mutations_detected,Married)
data_frame
##    Name Age Number_of_mutations_detected Married
## 1 Tamim  35                            4    TRUE
## 2 Imrul  39                            1    TRUE
## 3   Fiz  37                            0    TRUE

#Problem 17: Exploring Data Frame Structure

View(data_frame)
str(data_frame)
## 'data.frame':    3 obs. of  4 variables:
##  $ Name                        : chr  "Tamim" "Imrul" "Fiz"
##  $ Age                         : num  35 39 37
##  $ Number_of_mutations_detected: num  4 1 0
##  $ Married                     : logi  TRUE TRUE TRUE

#Problem 18: Renaming Columns

colnames(data_frame)<-c("Patient","Age","Mutations","Married")
data_frame
##   Patient Age Mutations Married
## 1   Tamim  35         4    TRUE
## 2   Imrul  39         1    TRUE
## 3     Fiz  37         0    TRUE

#Problem 19: Extracting a Subset of Data

Subset<-data_frame[,c(1,2)]
Subset
##   Patient Age
## 1   Tamim  35
## 2   Imrul  39
## 3     Fiz  37

#Problem 20: Extracting a Single Column

Mutations<-data_frame[,3]
Mutations
## [1] 4 1 0
data_frame$Mutations
## [1] 4 1 0

#Problem 21: Adding Row Names

rownames(data_frame)<-c("tamim","imrul","fiz")
data_frame
##       Patient Age Mutations Married
## tamim   Tamim  35         4    TRUE
## imrul   Imrul  39         1    TRUE
## fiz       Fiz  37         0    TRUE

#Problem 22: Problem 21: Adding Row Names

Number_of_mutations_detected<-c(5,1,0)
data_frame<-data.frame(Name,Age,Number_of_mutations_detected,Married)
data_frame
##    Name Age Number_of_mutations_detected Married
## 1 Tamim  35                            5    TRUE
## 2 Imrul  39                            1    TRUE
## 3   Fiz  37                            0    TRUE

#Problem 23: Sorting Patients by Age

data_frame$Age
## [1] 35 39 37

#Problem24:Academic Titles( solved with chatgpt help)

Hierarchy<-factor(c("lecturer","assistant_professor","associate_professor","professor"),levels=c("lecturer","assistant_professor","associate_professor","professor"),ordered=TRUE)
Hierarchy
## [1] lecturer            assistant_professor associate_professor
## [4] professor          
## 4 Levels: lecturer < assistant_professor < ... < professor

#Problem25:Lab Storage Temperature

Biobank_samples<-factor(c("cold","medium","hot"),levels=c("medium","cold","hot"),ordered=TRUE)
Biobank_samples
## [1] cold   medium hot   
## Levels: medium < cold < hot