#Question 1 #a no
gene1="ACGTACGT"
gene2="ACG"
#b no
combined_gene = paste(gene1, gene2)
print(combined_gene)
[1] "ACGTACGT ACG"
combined_gene = paste(gene1, gene2, sep ="")
print(combined_gene)
[1] "ACGTACGTACG"
#c no #Substring
gene1="ACGTACGT"
sub = substr(gene1, 2, 5)
sub
[1] "CGTA"
#d no #Pattern matching
gene1="ACGTACGT"
gene2="ACG"
grepl(gene2, gene1)
[1] TRUE
occ = gregexpr(gene2, gene1)
occ
[[1]]
[1] 1 5
attr(,"match.length")
[1] 3 3
attr(,"index.type")
[1] "chars"
attr(,"useBytes")
[1] TRUE
#Question 2 #Arithmatic Operation
a=100
b=21
#Addition
res_add = a+b
print(a+b)
[1] 121
#Substract
res_sub = a-b
print(a-b)
[1] 79
#Multiplication
res_mult = a*b
print(a*b)
[1] 2100
#Division
res_div = a/b
print(a/b)
[1] 4.761905
#Power
res_pow = a**b
res_pow2 = a^b
print(a**b)
[1] 1e+42
print(a^b)
[1] 1e+42
#Modulo
res_mod = a %% b
print(a %% b)
[1] 16
#Question 3 #Vector #Create
scores = c( 100, 90, 50, 20, 30, 88, 66, 75, 71, 91, 0, 45, 61 )
print(scores)
[1] 100 90 50 20 30 88 66 75 71 91 0 45 61
# Define the grading system
grading_system <- list(
"A+" = list("min" = 80, "max" = 100),
"A" = list("min" = 70, "max" = 79),
"A-" = list("min" = 60, "max" = 69),
"B" = list("min" = 50, "max" = 59),
"C" = list("min" = 40, "max" = 49),
"D" = list("min" = 33, "max" = 39),
"F" = list("min" = 0, "max" = 32)
)
# Function to calculate the letter grade
calculate_letter_grade <- function(score) {
for (key in names(grading_system)) {
min_score <- grading_system[[key]]$min
max_score <- grading_system[[key]]$max
if (score >= min_score && score <= max_score) {
return(key)
}
}
return("Invalid Score")
}
# Example scores
scores <- c( 100, 90, 50, 20, 30, 88, 66, 75, 71, 91, 0, 45, 61 )
# Calculate the letter grade for each score
for (score in scores) {
letter_grade <- calculate_letter_grade(score)
cat("Score:", score, "Letter Grade:", letter_grade, "\n")
}
Score: 100 Letter Grade: A+
Score: 90 Letter Grade: A+
Score: 50 Letter Grade: B
Score: 20 Letter Grade: F
Score: 30 Letter Grade: F
Score: 88 Letter Grade: A+
Score: 66 Letter Grade: A-
Score: 75 Letter Grade: A
Score: 71 Letter Grade: A
Score: 91 Letter Grade: A+
Score: 0 Letter Grade: F
Score: 45 Letter Grade: C
Score: 61 Letter Grade: A-
#Age vector
age = c(20, 25, 28, 30, 35, 45, 50, 55, 60, 61, 66, 71, 75 )
print(age)
[1] 20 25 28 30 35 45 50 55 60 61 66 71 75
#Correlation
age = c(20, 25, 28, 30, 35, 45, 50, 55, 60, 61, 66, 71, 75 )
print(age)
[1] 20 25 28 30 35 45 50 55 60 61 66 71 75
scores = c(100, 90, 50, 20, 30, 88, 66, 75, 71, 91, 0, 45, 61 )
print(scores)
[1] 100 90 50 20 30 88 66 75 71 91 0 45 61
cor(age, scores)
[1] -0.1958803
#Correlation nature is weak nagative correlation
scores[3:10]
[1] 50 20 30 88 66 75 71 91
age[3:10]
[1] 28 30 35 45 50 55 60 61
scores1 = c(50, 20, 30, 88, 66, 75, 71, 91 )
age1 = c(28, 30, 35, 45, 50, 55, 60, 61 )
cor(scores1,age1)
[1] 0.7954052
#Correlation nature is strong positive correlation