Question 1

Imagine, you have a DNA sequence consisting of letters from “A”, “C”, “G”, and “T”.

  1. Create two variables — one with 8 characters and another with 3 characters.
  2. Concatenate the two variables
  3. Create a substring from variable 1 starting from index 2 to 5

Answer 1

a)

seq1 = "CGATATGC"
print(seq1)
## [1] "CGATATGC"
seq2 = "GTA"
print(seq2)
## [1] "GTA"

b)

g_seq = paste(seq1, seq2, sep="")
print(g_seq)
## [1] "CGATATGCGTA"

c)

g_sub = substr(g_seq, 2, 5)
print(g_sub)
## [1] "GATA"

Question 2

Select any two integer numbers and store it in two variables. Now do the following arithmetic operation on the two numbers and store each result in variables and print it. 1. Add 2. substract 3. multiply 4. divide 5. power 6. modulo

Answer 2

var1 = 6
print(var1)
## [1] 6
var2 = 11
print(var2)
## [1] 11

1. Add

result_add = var1 + var2
print(result_add)
## [1] 17

2. substract

result_substract = var1 - var2
print(result_substract)
## [1] -5

3. multiply

result_multiply = var1*var2
print(result_multiply )
## [1] 66

4. divide

result_divide = var1/var2
print(result_divide )
## [1] 0.5454545

5. power

result_power = var2^var1
print(result_power)
## [1] 1771561

6. modulo

result_modulo = var1%%var2
print(result_modulo)
## [1] 6