assignment 01

question 03 grade

scores = c(100, 90,50, 20,30, 88, 66, 75,71,91, 0, 45, 61)
scores
##  [1] 100  90  50  20  30  88  66  75  71  91   0  45  61
for (i in 1:length(scores)) {
  
  s = scores[i]

  if (s > 50) {
    cat(i, s, "Pass!\n")
  } else {
    cat(i, s, "Fail\n")
  }
}
## 1 100 Pass!
## 2 90 Pass!
## 3 50 Fail
## 4 20 Fail
## 5 30 Fail
## 6 88 Pass!
## 7 66 Pass!
## 8 75 Pass!
## 9 71 Pass!
## 10 91 Pass!
## 11 0 Fail
## 12 45 Fail
## 13 61 Pass!

grad sequence

a= sort(scores)

for(i in 1:length(a)){
  s = a[i]
  
  if(s>= 80){
    cat(i, s, "A+\n")
  }
  else if(s>= 75 ){
     cat(i,s, "A\n")
  }
  else if(s>= 70){
     cat(i,s, "A-\n")
  }
  else if(s>= 65){
     cat(i,s, "B+\n")
  }
  else if(s>= 60){
     cat(i,s, "B\n")
  }
  else if(s>= 55){
     cat(i, s, "B-\n")
  }
  else if(s>= 50){
     cat(i,s, "C+\n")
  }
  else if(s>= 45){
     cat(i,s, "C\n")
  }
  
  else if(s>= 40){
     cat(i,s, "D\n")
  }
  else {
     cat(i,s, "F\n")
  }
 
}
## 1 0 F
## 2 20 F
## 3 30 F
## 4 45 C
## 5 50 C+
## 6 61 B
## 7 66 B+
## 8 71 A-
## 9 75 A
## 10 88 A+
## 11 90 A+
## 12 91 A+
## 13 100 A+

age vector

age = c( 20, 30, 40, 45, 50, 55,60,65, 70,75,80, 85,90)
age
##  [1] 20 30 40 45 50 55 60 65 70 75 80 85 90
scores
##  [1] 100  90  50  20  30  88  66  75  71  91   0  45  61

correlation - range frome -1 to 1

suggest clear rltn between two vector..

cor(scores, age)
## [1] -0.3111037
cor(scores, scores)
## [1] 1
cor(age, age)
## [1] 1

store new

new_scores = c(scores[3:11])
new_scores
## [1] 50 20 30 88 66 75 71 91  0
new_age= c(age[3:11])
new_age
## [1] 40 45 50 55 60 65 70 75 80
cor(new_scores, new_age)
## [1] 0.1179138
cor(new_age, new_age)
## [1] 1

QUES-01 DNA sequence of letters

gene1= "ACGGTGCA"
gene2= "TGC"

concatenate

combined_seq = paste(gene1, gene2, sep = "")
combined_seq
## [1] "ACGGTGCATGC"

substring

sub= substr(gene1, 2, 6)
sub
## [1] "CGGTG"
sub2 = substr(combined_seq,2,6)
sub2
## [1] "CGGTG"

yes, the pattern of gene2 exist in gene1

grepl(gene2, gene1)
## [1] TRUE

Ques-02 arithmetic operation

a= 13
b= 5

# add
res_add = a+b
print(res_add) 
## [1] 18
# sub
res_sub = a- b
print(res_sub) 
## [1] 8
# mul
res_mul = a*b
print(res_mul) 
## [1] 65
# div
res_div = a/b
print(res_div) 
## [1] 2.6
# power
res_pow = a**b
res_po = a^b
print(res_pow) 
## [1] 371293
# modulo( reminder)
res_mod = a %% b
print(res_mod) 
## [1] 3