#Question 1
#define 2 variable -- Question 1(A)
gene1= "GCAATGGC"
gene2= "GCA"
cat("First Variable is: ",gene1)
First Variable is: GCAATGGC
cat("Second Variable is: ",gene2)
Second Variable is: GCA
#concatenate two variables -- Question 1(B)
#paste is used for concatenating two variables
concatenate_sequence = paste(gene1,gene2,sep='')
cat('Concate Sequence is:',concatenate_sequence)
Concate Sequence is: GCAATGGCGCA
#Substring -- question 1(C)
Sub_string = substr(gene1, start=2, stop=5)
print(Sub_string)
[1] "CAAT"
#Check Pattern! Question 1(D)
#unlist is used for checking index
check_pattern=gregexpr(gene2,gene1)
print(check_pattern)
[[1]]
[1] 1
attr(,"match.length")
[1] 3
attr(,"index.type")
[1] "chars"
attr(,"useBytes")
[1] TRUE
if (check_pattern>0)
{
print('Yes! I have found the pattern')
cat('Pattern index starts from: ',unlist(check_pattern))
}else {
print("Pattern not found.")
}
[1] "Yes! I have found the pattern"
Pattern index starts from: 1
#Question 2
#Question 2
A=100
B=15
#Add
sum_v=A+B
#substract
diff_v=A-B
#multiply
product_v=A*B
#division
div_v=A/B
#power
power_v=A^2
#module
module_v=A%%B
cat('Sum is:',sum_v)
Sum is: 115
cat('Substarct is:',diff_v)
Substarct is: 85
cat('Multiply is:',product_v)
Multiply is: 1500
cat('Divide is:',div_v)
Divide is: 6.666667
cat('Power is:',power_v)
Power is: 10000
cat('Module is:',module_v)
Module is: 10