0% found this document useful (0 votes)
51 views

Assignment 2022 Combined.

The document contains sample questions from an assignment for a MOOC course on foundations of R software. The questions cover various R commands and functions related to vectors, arithmetic operations, rounding, and help documentation. Example commands are provided to demonstrate the use of functions like c(), prod(), sum(), floor(), ceiling(), etc. Multiple choice answers are given for each question.

Uploaded by

garvitagg27
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views

Assignment 2022 Combined.

The document contains sample questions from an assignment for a MOOC course on foundations of R software. The questions cover various R commands and functions related to vectors, arithmetic operations, rounding, and help documentation. Example commands are provided to demonstrate the use of functions like c(), prod(), sum(), floor(), ceiling(), etc. Multiple choice answers are given for each question.

Uploaded by

garvitagg27
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 112

MOOC Course - Foundations of R Software

July 2022

Assignment 1
1. Which of the following command is used to get help on the mean function?

a. "?mean"
b. ?’mean’
c. ?mean
d. mean?

2. Which of the following is the correct option to provide help in R?

a. help.search()
b. start.help()
c. search.help()
d. help.start()

3. Which of the following function provides the demonstration of the package


lm.glm in R?

a. demons(lm.glm)
b. Demo(‘lm.glm’)
c. demo(lm.glm)
d. demo(!lm.glm)

4. Which of the function provides the help on finding an example on the function
var?

a. example("var")
b. ex(var)
c. show.example(var)
d. show.example("var")

1
5. Which of the function does not provide the help in finding the contents of the
library bayesm?

a. library(help=bayesm)
b. library(help="bayesm")
c. library(help='bayesm')
d. library(help=bayesm?)

6. Which of the following command installs the package bayesm?

a. install.packages(bayesm)
b. install.packages("bayesm")
c. install.packages(bayesm?)
d. install.package("bayesm")

7*. Which of the following command is used to update the package bayesm?

a. update.packages(bayesm)
b. update.packages("bayesm")
c. update.packages(bayesm?)
d. update.package("bayesm")

8. Which of the following command detaches the package bayesm?

a. detache(package:bayesm, unload=TRUE)
b. detached("package:bayesm ", unload=TRUE)
c. Detach("package:bayesm", unload=FALSE)
d. detach("package:bayesm", unload=TRUE)

2
9. Which of the following command removes the package bayesm?

a. remove.packages(bayesm)
b. remove.packages("bayesm")
c. remove.packages(bayesm?)
d. remove.package("bayesm")

10. Which of the following command provides the description of the package
cluster?

a. packagedescription("cluster")
b. packageDescribe("cluster")
c. PackageDescription("cluster")
d. packageDescription("cluster")

3
MOOC Course – Foundations of R Software

Answers of Assignment 1

1. c

2. d

3. c

4. a

5. d

6. b

7. b

8. d

9. b

10. d

4
MOOC Course - Foundations of R Software

July 2022

Assignment 2

1. Which of the following command is used to search the web for information and
answers about keyword mean ?

a. RsiteSearch("mean")
b. RSiteSearch(mean)
c. RSiteSearch("mean")
d. rsitesearch("mean")

2. Which of the following is the correct matching of the commands in column A and
the outputs in Column B when executed in R console where x = 20 and y = "20"?

Column A Column B
(1) is.character(x) (i) TRUE
(2) is.character(y) (ii) FALSE

a. (1)-(ii), (2)-(i)
b. (1)-(i), (2)-(ii)
c. (1)-(i), (2)-(i)
d. (1)-(ii), (2)-(ii)

1
3. Which of the following is the correct matching of the commands in column A and
the outputs in Column B when executed in R console where x = 20 and y = "20"?

Column A Column B
(1) is.numeric(x) (i) TRUE
(2) is.numeric(y) (ii) FALSE

a. (1)-(ii), (2)-(i)
b. (1)-(i), (2)-(ii)
c. (1)-(i), (2)-(i)
d. (1)-(ii), (2)-(ii)

4. Which of the following is the correct matching of the commands in column A and
the outputs in Column B when executed in R console where x = 20 and y = "20"?

Column A Column B
(1) mode(x) (i) numeric
(2) mode(y) (ii) character

a. (1)-(ii), (2)-(i)
b. (1)-(i), (2)-(ii)
c. (1)-(i), (2)-(i)
d. (1)-(ii), (2)-(ii)

2
5. Which of the following is the correct matching of the commands in column A and
the outputs in Column B when executed in R console where x = 20 and y = "20"?

Column A Column B
(1) storage.mode(x) (i) double
(2) storage.mode(y) (ii) character

a. (1)-(ii), (2)-(i)
b. (1)-(i), (2)-(ii)
c. (1)-(i), (2)-(i)
d. (1)-(ii), (2)-(ii)

6. Which of the following is the correct matching of the commands in column A and the
outputs in Column B when executed in R console where x = 20 and y = 20 + Inf?

Column A Column B
(1) is.finite(x) (i) TRUE
(2) is.infinite(y) (ii) FALSE

a. (1)-(ii), (2)-(i)
b. (1)-(i), (2)-(ii)
c. (1)-(i), (2)-(i)
d. (1)-(ii), (2)-(ii)

3
7. What will be the outcome of following commands when executed over the R
console

x=43
y=x^3
z=y^2+x^4
z

a. 6231634898
b. 6321364898
c. 6324781850
d. 6342718850

8. Which one of the following is the correct outcome of the command

5-3+4/6*7-3^3*4-7/6*2-3**3/2+6-7+2 ?
a. -107.1667
b. -116.1667
c. -125.5
d. 116.1667

9. Which one of the following is the correct outcome of the command

15/(-5)*2+8^(-3)/(65/32)-4**3+4-81^(-1/4)+2^(-4**3) ?

a. -66.33237
b. -77.33237
c. -65.32148
d. None of these

4
10. Which one of the following is the correct outcome of the command

c(12,13,15,17)/10 + c(1.2,1.3,1.5,1.7)*10?

a. 24 26 30 34
b. 2.4 2.6 3.0 3.4
c. 13.2 14.3 16.5 18.7
d. None of these

MOOC Course – Foundations of R Software

Answers of Assignment 2

1. c

2. a

3. b

4. b

5. b

6. c

7. c

8. b

9. a

10. c

5
MOOC Course - Foundations of R Software

July 2022

Assignment 3

1. Which one of the following is the correct outcome of the command


c(1,2,3,4)/c(1,2,2,4)*c(2,1,3,2)**c(1,2,3,3)-
c(2,2,32,5) ?

a. 0.0 0.0 -18.5 1.0


b. 0.0 -1.0 8.5 3.0
c. -1.000 0.000 -30.875 -4.250
d. Error:...

2. Which one of the following is the correct outcome of the command

c(9,16,6,20)/c(3,4)+ c(4,2,4,2)^c(2,3)+c(2,4,8,6)/c(2,2)-
c(3,8,2,4)*c(3,1) ?

a. 11 6 16 12
b. 9 2 8 6
c. -23 -14 -24 -10
d. None of these

1
3. Which one of the following command will give a result without a warning?

a. c(1,3,5,7)^c(8,9,4) - c(2,3,4,5)**c(12,3,14,5)- c(240,30,


76,98)/c(8,3)
b. c(1,3,5,7)^c(8,4) - c(2,3,4,5)**c(12,3,14,5)- c(240,30,
76,98)/c(8,3)
c. c(1,3,5,7)^c(8,4) - c(2,3,4,5)**c(12,3,5)- c(240,30,
76,98)/c(8,3)
d. c(1,3,5,7)^c(8,9,4,7) - c(2,3,4,5)**c(12,3,14,5)-
c(240,30, 76,98)/c(8,3,7)

4. Which one of the following is the correct outcome of the command

sqrt(c(2,6,7,8)*c(4,2,2,4)+ c(2,4,2,4)*c(-2,2)+
c(1,2,4,4)**c(9,2,4,1))?

a. 2.236068 4.898979 16.309506 6.633250


b. 3.605551 4.898979 5.099020 6.633250
c. 3.605551 2.828427 16.552945 5.291503
d. Error:...

5. Which one of the following is the correct outcome of the command

c(1,2,1,2)*-c(1,2,-1,-2)**c(-1,-2,1,2)*-c(1,2,-1,-2)?

a. 1 1 1 16
b. 1 1 1 -16
c. -1 -16 1 16
d. -1 -1 -1 -16

2
6. Which one of the following is the correct outcome of the command

c(5,6,7,8)%/%4- c(64,64,24,24)%/%c(4,3,5,7)+
c(153,646,817,788)%%c(71, 63) ?

a. 4 4 33 31
b. -4 -4 -33 -31
c. -4 -4 33 31
d. 4 4 -33 -31

7. Which one of the following is the correct outcome of the command

min(c(98,88,44,76)**c(-2,3))/min(c(49,44,22,38)^c(-2,-3)) -
prod(c(1,2,1,2)^c(1,2))/max(c(9,4,4,9,26)*min(c(4,3,2,6))
)+max(c(22,23,24,25)^c(2,3)) ?
a. -16680439
b. 16680439
c. 15633.56
d. None of these

8. Which one of the following is the correct outcome of the command?


round(prod(c(1,2,1,2)^c(1,2)) * sum(c(1,2,1,2)^c(2,3)) +
prod(c(1,2,1,2)^c(1,2,3,7)) + ceiling(c(5,6,7,8)^c(2,3)))

a. -199 -8 -175 288


b. 825 1016 849 1312
c. -825 1016 -849 1312
d. None of these

3
9. Which one of the following is the correct outcome of the command
floor(c(5,6,7,8)^c(2,3))- ceiling(c(5,6,7,8)^c(2,3))+
ceiling(c(2,3,4,5)^-c(1,-2)) - round(c(5,6,7,8)^c(2,3)) +
floor(c(5,6,7,8)^c(2,3))?

a. 51 441 99 1049
b. 1 9 1 25
c. -1 -9 -1 -25
d. None of these

10. Which one of the following is the correct outcome of the command

ceiling(c(4,8,4,5)^-c(3,9) + sqrt(c(36,16,81,64)**c(2,3))*
sqrt(c(2,3,4,5)^-c(1,2)) + round(c(4,7,8,9)*round(c(7,9))))
?
a. 54 85 97 184
b. -2 -41 -15 22
c. 3 42 16 -21
d. None of these

11. Which one of the following is the correct outcome of the command

ceiling(prod(c(2,3,8,9))- sum(c(2,22,23,24,151))) -
floor(prod(c(2,3,8,9))+ round(c(2,22,23,24,151)))?

a. -220 -200 -199 -198 -71


b. 640 620 619 618 491
c. -224 -244 -245 -246 -373
d. None of these

4
12. Which one of the following is the value of X2 when the following commands are
executed over the R console?

X1 = c(23,25,18,24)

X2 = sqrt(X1^2)+X1*6/X1^2-X1**(1/2)+abs(X1)

a. 41.46504 45.24000 32.09069 43.35102


b. 40.94330 44.76000 31.42403 42.85102
c. -4.534962 -4.760000 -3.909307 -4.648979
d. None of these

13. Which one of the following is the correct outcome of the command

c(21,22,24,34)^c(-3,-2,2,3)/c(4,3,2,1) +
c(2,4,1,6)%/%c(3,4)*c(2,5,3,6)+
max(c(20,140,114,215)^c(1,2))/min(c(6,2,7,15)^c(2,2))?

a. 5.000027 10.000689 293.000000 39315.000000


b. 11556.25 -11551.25 11844.25 -50854.25
c. 11556.25 11561.25 11844.25 50866.25
d. None of these

5
14. Which one of the following is the correct command to obtain the following matrix?

 21 24 27 
 
x =  22 25 28 
 23 26 29 
 

a. x=matrix(21:29,3,3,byrow=T)
b. x=mat(21:29,3,3, byrow=T)
c. x=matrix(21:29,3,3,byrow=F)
d. x=mat(21:29,3,3,byrow=F)

15. Which one of the following is the correct command to obtain the following matrix?

15 11 17 
z = 
 8 19 12 

a. z = matrix(nrow=2, ncol=3, data=c(15,11,17,8,19,12),


byrow=T)
b. z = matrix(nrow=3, ncol=2, data=c(15,8,11,19,17,12) ,
byrow=T)
c. z = matrix(nrow=2, ncol=3, data=(15,8,11,19,17,12) ,
byrow=T)
d. z = matrix(nrow=3, ncol=2, data=(15,8,11,19,17,12) ,
byrow=T)

6
16. Which one of the following is the correct command to obtain the third column and
first row of the following matrix?

 10 20 30 
 
x =  40 50 60 
 70 80 90 
 

a. x(3, ) and x( ,1) respectively.


b. x(3, ) and x(1, ) respectively.
c. x[, 3] and x[1, ] respectively.
d. x[ ,1] and x[3, ] respectively.

17. Which one of the following is the correct outcome of the command X[3,2] for
the matrix constituted by the command X=matrix(61:69,3,3,byrow=F)?

a. 63
b. 66
c. 67
d. 68

18. Which one of the following is the correct outcome of the commands dim(x) and
dim(y) for the matrices obtained by x=matrix(101:150,25,2,byrow=T)
and y=matrix(201:250,25,2,byrow=F) ?

a. 25 2 and 2 25 respectively.
b. 2 25 and 25 2 respectively.
c. 2 25 and 2 25 respectively.
d. 25 2 and 25 2 respectively.

7
MOOC Course - Foundations of R Software

Answers of Assignment 3
1. b

2. a

3. b

4. a

5. b

6. c

7. c

8. b

9. b

10. a

11. c

12. a

13. c

14. c

15. a

16. c

17. b

18. d

8
MOOC Course - Foundations of R Software

July 2022

Assignment 4

1. Which one of the following is the correct outcome of the command rowSums(X)
for the matrix constituted by the command X=matrix(61:69,3,3,byrow=F)?

a. 69 65 61
b. 186 195 204
c. 61 65 69
d. 192 195 198

2. Which one of the following is the correct outcome of the command colSums(X)
for the matrix constituted by the command X=matrix(61:69,3,3,byrow=F)?

a. 69 65 61
b. 186 195 204
c. 61 65 69
d. 192 195 198

3. Which one of the following is the correct outcome of the command rowMeans(X)
for the matrix constituted by the command X=matrix(61:69,3,3,byrow=F)?

a. 64 65 66
b. 62 65 68
c. 186 195 204
d. 192 195 198

1
4. Which one of the following is the correct outcome of the command colMeans(X)
for the matrix constituted by the command X=matrix(61:69,3,3,byrow=F)?

a. 64 65 66
b. 62 65 68
c. 186 195 204
d. 192 195 198

5. Which one of the following is the correct outcome matrix of the command

x = diag(5, nrow=2, ncol=2) ?

 5 5
a. x =  
 0 5

0 5
b. x =  
5 0

5 5
c. x= 
5 5

5 0
d. x= 
0 5

6. Which one of the following is the correct outcome of the command t(x) for
2
x=matrix(nrow=3, ncol=2, data=30:35, byrow=T) ?

a.
[,1] [,2] [,3]
[1,] 30 32 34
[2,] 31 33 35

b.
[,1] [,2]
[1,] 30 31
[2,] 32 33
[3,] 34 35

c.
[,1] [,2]
[1,] 30 33
[2,] 31 34
[3,] 32 35

d.
[,1] [,2] [,3]
[1,] 30 31 32
[2,] 33 34 35

7. Which one of the following is the correct command to obtain the multiplication of
two square matrices x and y of the same order?

a. x**y

b. x*%*y

c. x%*%y

d. x%**%y

3
8. Which one of the following is the correct command to obtain the multiplication of

4 7 12 13 
two matrices x=  and y =   along with its correct answer?
8 2 16 11 

a. x*y
and its correct answer is
[,1] [,2]
[1,] 48 128
[2,] 91 22

b. x*%*y
and its correct answer is
[,1] [,2]
[1,] 48 91
[2,] 128 22

c. x%*%y
and its correct answer is
[,1] [,2]
[1,] 160 129
[2,] 128 126

d. x%%*%%y
and its correct answer is
[,1] [,2]
[1,] 160 128
[2,] 129 126

4
9. Let x= matrix(nrow=3, ncol=3, data=49:41, byrow=T) then which
one of the following is the correct outcome of 3*x ?

a.
[,1] [,2] [,3]
[1,] 147 144 141
[2,] 138 135 132
[3,] 129 126 123
b.
[,1] [,2] [,3]
[1,] 147 138 129
[2,] 144 135 126
[3,] 141 132 123

c.
[,1] [,2] [,3]
[1,] 141 132 123
[2,] 144 135 126
[3,] 147 138 129

d.
[,1] [,2] [,3]
[1,] 129 126 123
[2,] 138 135 132
[3,] 147 144 141

5
10. Which one of the following is the correct command to obtain of the addition of

4 8 12 16 
two matrices x=  and y =   along with its correct answer?
7 2  13 11 

a.
x + y
and its correct answer is
[,1] [,2]
[1,] 16 24
[2,] 20 13

b.
x %+% y
and its correct answer is
[,1] [,2]
[1,] 16 24
[2,] 20 13

c.
x %%+%% y
and its correct answer is
[,1] [,2]
[1,] 20 13
[2,] 16 24

d.
x %+%+ y
and its correct answer is
[,1] [,2]
[1,] 20 13
[2,] 16 24

6
11. Let x= matrix(nrow=4, ncol=4, data=16:31, byrow=F) then which
one of the following is the correct outcome of 2+4%*%x ?

a.
[,1] [,2] [,3] [,4]
[1,] 66 80 96 112
[2,] 68 84 100 116
[3,] 72 88 104 120
[4,] 76 92 108 124

b.
[,1] [,2] [,3] [,4]
[1,] 66 82 98 114
[2,] 70 86 102 118
[3,] 74 90 106 122
[4,] 78 94 110 126

c. Error...

d. None of these

12. Which one of the following is the correct outcome of X[3 ,] for the matrix
specified by

X=matrix(nrow=3, ncol=3, data=c(10,20,30,40,50,60,70,80,90),


byrow=F) ?

a. [1] 30 60 90
b. [1] 10 20 30
c. [1] 40 50 60
d. None of these

7
13. Which one of the following is the correct outcome of x[1:2,2:3] for the matrix
specified by x= matrix(nrow=4, ncol=4, data=16:31, byrow=T)?

a.
[,1] [,2]
[1,] 21 22
[2,] 17 18

b.

[,1] [,2]

[1,] 17 18

[2,] 21 22

c.
[,1] [,2]
[1,] 17 21
[2,] 18 22

d.
[,1] [,2]
[1,] 17 17
[2,] 17 17

8
 20 30 
 
14. Which one of the following is the correct command to get the matrix  50 60 
 80 90 
 
from the matrix specified by

X=matrix(nrow=4, ncol=3, data=c(10,20,30,40,50,60,70,80,90,


100,110,120), byrow=T) ?

a. X[2:3, 1:3]
b. X[1:3, 2:3]
c. X[1:1, 2:2, 3:3]
d. X[3:3, 2:2, 1:1]

9
15. Which one of the following is the correct output of the command cbind(x,y)
for the matrices specified by

x=matrix(nrow=3, ncol=2, data=30:35, byrow=T)

y=matrix(nrow=3, ncol=2, data=c(10,20,30,40,50,60), byrow=T) ?

a.

[,1] [,2]
[1,] 30 31
[2,] 32 33
[3,] 34 35
[4,] 10 20
[5,] 30 40
[6,] 50 60

b.

[,1] [,2] [,3] [,4]


[1,] 10 20 30 31
[2,] 30 40 32 33
[3,] 50 60 34 35

c.

[,1] [,2] [,3] [,4]


[1,] 30 31 10 20
[2,] 32 33 30 40
[3,] 34 35 50 60

d.

[,1] [,2]
[1,] 10 20
[2,] 30 40
[3,] 50 60
[4,] 30 31
[5,] 32 33
[6,] 34 35

10
16. Which one of the following is the correct output of the command rbind(y,x)
for the matrices specified by

x=matrix(nrow=3, ncol=2, data=30:35, byrow=T)

y=matrix(nrow=3, ncol=2, data=c(10,20,30,40,50,60), byrow=T) ?

a.

[,1] [,2]
[1,] 30 31
[2,] 32 33
[3,] 34 35
[4,] 10 20
[5,] 30 40
[6,] 50 60

b.

[,1] [,2] [,3] [,4]


[1,] 10 20 30 31
[2,] 30 40 32 33
[3,] 50 60 34 35

c.

[,1] [,2] [,3] [,4]


[1,] 30 31 10 20
[2,] 32 33 30 40
[3,] 34 35 50 60

d.

[,1] [,2]
[1,] 10 20
[2,] 30 40
[3,] 50 60
[4,] 30 31
[5,] 32 33
[6,] 34 35

11
 13 1 12 5 
 
 4 20 14 6 
17. If x =  5 3 16 7  then which one of the following is the correct
 
 16 8 12 8 

command and its outcome for obtaining the inverse of the sub-matrix of x formed by
first, second, and third rows and second, third, and fourth columns?

a.
solve(x[1:3,2:4])=
[,1] [,2] [,3]
[1,] -0.02777778 0.05555556 -0.02777778
[2,] 1.69444444 0.11111111 -1.30555556
[3,] -3.86111111 -0.27777778 3.13888889

b.
inv(x[1:3,2:4])=
[,1] [,2] [,3]
[1,] -0.02777778 0.05555556 -0.02777778
[2,] 1.69444444 0.11111111 -1.30555556
[3,] -3.86111111 -0.27777778 3.13888889

c.
inv(x[1:3,2:4])=
[,1] [,2] [,3]
[1,] -0.02777778 1.6944444 -3.8611111
[2,] 0.05555556 0.1111111 -0.2777778
[3,] -0.02777778 -1.3055556 3.1388889

d.
solve((x[1:3,2:4]))=
[,1] [,2] [,3]
[1,] -0.02777778 1.6944444 -3.8611111
[2,] 0.05555556 0.1111111 -0.2777778

12
[3,] -0.02777778 -1.3055556 3.1388889

18. Which one of the following is the correct outcome of the command

(x < 15) || (x > 12) & (x < 15) && (x > 12)||(x == 17) when
x = 13 and when x = -13 ?

a. FALSE and FALSE respectively.

b. TRUE and TRUE respectively.

c. FALSE and TRUE respectively.

d. TRUE and FALSE respectively.

19. Suppose x = 13:16 . Then which one of the following is the correct outcome
of the command

(x > 13)&(x < 15) ?

a. FALSE TRUE FALSE FALS

b. TRUE FALSE TRUE TRUE

c. TRUE TRUE TRUE FALSE

d. FALSE FALSE FALSE TRUE

20. Suppose x = 3:18 . Then which one of the following correctly specifies the
outcome of the following statement: x[(x > 12) & (x < 17)] and x[(x >
15) | (x < 5)] ?

a. are different for both as 13 14 15 16 and 3 4 16 17 18 respectively.

b. are the same for both as 13 14 15 16

c. are different for both as 5 6 7 8 and 13 14 15 16 respectively.

13
d. are the same for both as 5 6 7 8

21. Suppose x = 10:50 . Then which one of the following is the correct command
to know that which of the values in x are more than 30 and less than 40?

a. x[(x > 30) & (x < 40)]

b. (x > 40) & (x < 50)

c. x[(x >= 40) & (x >= 40)]

d. x[(x <= 40) & (x <= 40)]

22 . Suppose x = 45:80 . Then which one of the following is the correct outcome

of (x > 80) && (x < 70) and (x > 80) || (x < 70) ?

a. TRUE and FALSE respectively.

b. FALSE and FALSE respectively.

c. TRUE and TRUE respectively.

d. FALSE and TRUE respectively.

23. Suppose x = 13:17 then which one of the following is the correct outcome of

x[(x > 12) || (x < 15)] ?

a. TRUE

b. FALSE

c. 13 14 15 16 17

14
d. 17 16 15 14 13

24. Suppose x = c(10,20,30,40,50) and y = c(40,50,60,70,80) then


which one of the following is the correct outcome of x != y ?

a. TRUE TRUE TRUE TRUE TRUE

b. FALSE FALSE FALSE FALSE FALSE

c. TRUE

d. FALSE

25. Suppose x = c(10,20,30,40,50) and y = c(40,50,60,70,80) then


which one of the following is the correct outcome of x == y ?

a. TRUE TRUE TRUE TRUE TRUE

b. FALSE FALSE FALSE FALSE FALSE

c. TRUE

d. FALSE

15
MOOC Course - Foundations of R Software

Answers of Assignment 4
1. d
2. a
3. b
4. a
5. d
6. a
7. c
8. c
9. a
10. a
11. c
12. a
13. b
14. b
15. c
16. d
17. a
18. b
19. a
20. a
21. a
22. d
23. c
24. a
25. b

16
MOOC Course - Foundations of R Software

July 2022

Assignment 5

1. Suppose x is any vector as x=c(10, 80, 90, 101:200, NA) then which
one of the following is the correct outcome of the command mean(x,
na.rm=FALSE)?
a. 147.8641

b. 96.2

c. Error...

d. NA

2. Suppose x is any vector as x=c(10, 80, 90, 101:200, NA) then which
one of the following is the correct outcome of the command mean(x,
na.rm=TRUE)?

a. 147.8641

b. 96.2

c. Error...

d. NA

1
3. Suppose x is any vector as x=c(10, 80, 90, 101:200, NA) then which
one of the following is the correct outcome of the command
mean(na.omit(x))?

a. 147.8641

b. 96.2

c. Error...

d. NA

4. If x = 23 then which one of the following is the correct outcome of y where

y=if ( x==23 ) { x = x^3+3 } else { x = x^2-3 } ?

a. 12164

b. 12170

c. 526

d. 123

2
5. Which one of the following is the correct syntax to compute y for the following
function?


 2 x + | x − 66 |
3/2 4
if x0
y=
3exp( x ) − x
 x0
3 5/2
if

a. if ( x <= 0 ) [ y = 2 * x^(3/2) + abs(x^4 - 66) ] else [


y = 3 * exp(x^3) - sqrt(x^(5/2))]
b. if ( x <= 0 ) ( y = 2 * x^(3/2) + abs(x^4 - 66) ) else (
y = 3 * exp(x^3) - sqrt(x^(5/2)))
c. if ( x <= 0 ) { y = 3 * exp(x^3) - sqrt(x^(5/2))} else {
y = 2 * x^(3/2) + abs(x^4 - 66)}
d. if ( x <= 0 ) ( y = 3 * exp(x^3) - sqrt(x^5/2)) else ( y
= 2 * x^3/2 + abs(x^4 - 66))

6. Suppose x = c(12,4,16,8,20,5,14) then which one of the following is the


correct output of

ifelse(x < 10, 2+x, 2*x) ?

a. [1] 14 8 18 16 22 10 16

b. [1] 14 6 18 10 22 7 16

c. [1] 24 8 32 16 40 10 28

d. [1] 24 6 32 10 40 7 28

3
7. Which one of the following is the correct outcome of the command
switch(2, "UP", "MP", "J&K", "Bihar", 20, 40, 60+40)?

a. 100

b. "UP"

c. "MP"

d. 40

8. Which one of the following is the correct outcome of the command


switch(7, "UP", "MP", "J&K", "Bihar", 20, 40, 60+40)?

a. 100

b. "UP"

c. 60+40

d. 40

9. Which one of the following is the correct outcome of the command


switch("S3", "S1"= "UP", "S2" = "MP", "S3" = "J&K", "S4" =
"Bihar", N1 = 20, N2 = 40, N3 = 60+40)?

a. "S3"

b. "MP"

c. "J&K"

d. 100

4
10. Which one of the following is the correct outcome of the command
switch("N3", "S1"= "UP", "S2" = "MP", "S3" = "J&K", "S4" =
"Bihar", N1 = 20, N2 = 40, N3 = 60+40)?

a. "S3"

b. "MP"

c. "J&K"

d. 100

11. Suppose x is any vector as x=c("UP", "MP", "J&K", "Bihar", 20,


40, 60+40) then which one of the following is the correct outcome of the
command which(x == 100)?

a. 60+40

b. 7

c. Error...

d. NA

5
MOOC Course - Foundations of R Software

Answers of Assignment 5
1. d

2. a

3. a

4. b

5. b

6. d

7. c

8. a

9. c

10. d

11. b

6
MOOC Course - Foundations of R Software

July 2022

Assignment 6

1. Which one of the following is the correct outcome of

for(i in 12:14) {print(1 - 2i + i^2)} ?

a.

[1] 121

[1] 144

[1] 169

b.

[1] -23 + i2

[1] -25 + i2

[1] -27 + i2

c.

[1] 145-2i

[1] 170-2i

[1] 197-2i

d.

[1] 169

[1] 144

[1] 121

1
2. Which one of the following is the correct outcome of

for(i in 10:14) {print(i + 2*i + 3*i**3)} ?

a.

[1] i + 2*i + 3*i**3

[1] i + 2*i + 3*i**3

[1] i + 2*i + 3*i**3

[1] i + 2*i + 3*i**3

b.

[1] 3030

[1] 4026

[1] 5220

[1] 6630

[1] 8274

c.

[1] 120

[1] 132

[1] 144

[1] 156

[1] 168

d. Error...

2
3. Which one of the following is the correct outcome of the following commands
about while loop?

y = 5

while (y < 15) {


print(c("R Course","through NPTEL is helpful."))
y = y + 1
print(c("R Course","through NPTEL is not helpful."))
y = y + 3
}

a.
[1] "R Course" "through NPTEL is not helpful."
[1] "R Course" "through NPTEL is helpful."
[1] "R Course" "through NPTEL is not helpful."
[1] "R Course" "through NPTEL is helpful."
[1] "R Course" "through NPTEL is not helpful."
[1] "R Course" "through NPTEL is helpful."

b.
[1] "R Course" "through NPTEL is not helpful."
[1] "R Course" "through NPTEL is not helpful."
[1] "R Course" "through NPTEL is not helpful."
[1] "R Course" "through NPTEL is helpful."
[1] "R Course" "through NPTEL is helpful."
[1] "R Course" "through NPTEL is helpful."

c.
[1] "R Course" "through NPTEL is helpful."
[1] "R Course" "through NPTEL is not helpful."
[1] "R Course" "through NPTEL is helpful."
[1] "R Course" "through NPTEL is not helpful."
[1] "R Course" "through NPTEL is helpful."
[1] "R Course" "through NPTEL is not helpful."

d.

[1] "R Course" "through NPTEL is helpful."


[1] "R Course" "through NPTEL is helpful."
[1] "R Course" "through NPTEL is helpful."
[1] "R Course" "through NPTEL is not helpful."
[1] "R Course" "through NPTEL is not helpful."
[1] "R Course" "through NPTEL is not helpful."

3
4. Which one of the following is the correct outcome of the following while loop?

x = 20

while(x < 35) {x = x^2+10; if (x == 30) break; print(x); }

a.

[1] 410

b.

[1] 20

c.

[1] 410

[1] 410

d.

[1] 20

[1] 20

[1] 35

[1] 35

4
5. Which one of the following is the correct specification to compute

y = exp( x) + x 2 + x3/2 − 4000 and what is its value for x = 17 ?

a. y<-function{x}{sqrt(exp(x)+x^2)+x^3/2-4000}, y=3371.298
b. y<-f(x)[sqrt(exp(x)+x^2)+x^(3/2)-4000] , y=984.891
c. y<-function(x){sqrt(exp(x)+x^2)+x^3/2-4000}, y=3371.298
d. y<- function(x){sqrt(exp(x)+x^2)+x^(3/2)-4000}, y
=984.891

6. Which one of the following is the correct outcome of z(14,11) of the function spe
cified as z=function(x,y){sqrt(x^3-y^3+log(x))+log(-(5*x^-2+6*y^-
2-60))-(x^3-y^2)^(3/4)} ?
a. -4511644550
b. -324.8028
c. -2758.699
d. None of these

7. Which one of the following is the correct outcome of the command

abs(seq(-30,-35))?

a. [1] 30 31 32 33 34 35

b. [1] -30 -31 -32 -33 -34 -35

c. [1] 35 34 33 32 31 30

d. [1] -35 -34 -33 -32 -31 -30

5
8. Which one of the following is the correct output of the command
sqrt(abs(seq(-15,15, by = 6))) ?

a. [1] -3.872983 -3.000000 -1.732051 -1.732051 3-.000000 -


3.872983

b. [1] 3.872983 3.000000 1.732051 1.732051 3.000000 3.872983

c. [1] 1.732051 3.000000 3.872983 1.732051 3.000000 3.872983

d. [1] 1.732051 3.000000 3.872983 3.872983 3.000000 1.732051

9. Which one of the following is the correct output of the command seq(20,-20,
by = -4)?

a. [1] -20 -16 -12 -8 -4 0 4 8 12 16 20

b. [1] -20 -16 -12 -8 -4 0

c. [1] 17 12 7 3 -3 -7 -12 -17

d. [1] 20 16 12 8 4 0 -4 -8 -12 -16 -20

10. Which one of the following is the correct output of the command

seq(to = 200, length = 10)?

a. [1] -209 -208 -207 -206 -205 -204 -203 -202 -201 -200

b. [1] 191 192 193 194 195 196 197 198 199 200

c. [1] -191 -192 -193 -194 -195 -196 -197 -198 -199 -200

d. [1] 200 201 202 203 204 205 206 207 208 209

6
11. Which one of the following is the correct output of the command seq(to = -
100, length = 10) ?

a. [1] -109 -108 -107 -106 -105 -104 -103 -102 -101 -100

b. [1] 109 108 107 106 105 104 103 102 101 100

c. [1] 100 101 102 103 104 105 106 107 108 109

d. [1] -100 -101 -102 -103 -104 -105 -106 -107 -108 -109

12. Which one of the following is the correct output of the command

seq(to = 112, length = 11, by = 12) ?

a. [1] 4 16 28 40 52 64 76 88 100 112 114

b. [1] 114 112 100 88 76 64 52 40 28 16 4

c. [1] -8 4 16 28 40 52 64 76 88 100 112


d. [1] 112 100 88 76 64 52 40 28 16 4 -8

13. Which one of the following is the correct output of the command

seq(from = -5, length = 5, by = -0.5) ?

a. [1] -5.0 -4.5 -4.0 -3.5 -3.0

b. [1] -5.0 -5.5 -6.0 -6.5 -7.0

c. [1] 3.0 3.5 4.0 4.5 5.0

d. [1] 7.0 6.5 6.0 5.5 5.0

7
14. Which one of the following is the correct output of Y for the following commands

X = c(78, 67, 15, 120, 3, 160, 20, 48, 9)


Y = seq(along = X) ?

a. [1] 1 2 3 4 5 6 7 8 9

b. [1] 7 6 3 8 1 9 4 5 2

c. [1] 2 5 4 9 1 8 3 6 7

d. [1] 9 8 7 6 5 4 3 2 1

15. Which one of the following is the correct output of Y[X[3]] and Y[X[7]]
for the command

Y = c(90, 17, 51, 80, 32, 60, 87)

X = c(5, 7, 1, 4, 6, 3, 2) ?

a. 51 and 87 respectively.

b. 1 and 2 respectively.

c. 17 and 90 respectively.

d. 90 and 17 respectively.

8
16. Which one of the following is the correct outcome of the command x[(x>50)]
where
x = c(20, 65, 27, 55, 38, 37, 18, 52, 160, 237, 170, 61, 88,
52, 49, 12, 4, 24, 18, 22) ?

a. [1] 65 55 52 160 237 170 61 88 52

b. [1] 9

c. [1] TRUE

d. [1] FALSE

17. Which one of the following is the correct outcome of the command
x[(x - 50 > 30)] where
x = c(20, 65, 27, 55, 38, 37, 18, 52, 160, 237, 170, 61, 88,
52, 49, 12, 4, 24, 18, 22) ?

a. [1] 65 55 38 37 52 160 237 170 61 88 52 49

b. [1] 160 237 170 88

c. [1] NULL

d. [1] 12

9
18. Which one of the following is the correct outcome of the command
x[(x^2 + 6*x < 500)] where
x = c(20, 65, 27, 55, 38, 37, 18, 52, 160, 237, 170, 61, 88,
52, 49, 12, 4, 24, 18, 22) ?

a. [1] 20 65 27 55 38 37 52 160 237 170 61 88 52


49 24 22

b. [1] 20, 65, 27, 55, 38, 37, 18, 52, 160, 237, 170, 61, 88,
52, 49, 12, 4, 24, 18, 22

c. [1] 18 12 4 18

d. [1] NULL

19. If y = 15:25 then which one of the following is the correct outcome of the
command y[ - (3:10)] ?

a. [1] 17 18 19 20 21 22 23 24

b. [1] 15 16 25

c. [1] 18 19 20 21 22 23 24 25

d. [1] -25 -16 -15

10
MOOC Course - Foundations of R Software

Answers of Assignment 6
1. c

2. b

3. c

4. a

5. d

6. b

7. a

8. b

9. d

10. b

11. a

12. c

13. b

14. a

15. d

16. a

17. b

18. c

19. b

11
MOOC Course - Foundations of R Software

July 2022

Assignment 7

1. Which one of the following is the correct command to generate a sequence of three
yearly dates 1-July-2020, 1- July-2021 and 1- July-2022?

a. seq(as.Date("2020-03-01"), as.Date("2022-03-01"), by = "years")

b. seq(as.date("2020-03-01"), as.date("2021-03-01"),

as.date("2022-03-01"),by = "years")

c. seq(as.Date(`2020-03-01’), as.Date(`2022-03-01’), by = `1’)

d. seq(As.Date("2020-03-01"), As.Date("2022-03-01"), by = "years")

2. Which one of the following is the correct command to generate the dates of 6
consecutive months starting from 15 March 2022?

a. seq(As.Date("2022-03-15"), by = "months", length = 6)

b. seq(as.date("2022-03-15"), by = "months", length = 6)

c. seq(as.Date("2022-03-15"), by = "months", length = 6)

d. seq(as.Date("2022-03-15") to as.Date("2022-08-15") by = "30")

1
3. Which one of the following is the correct outcome of the command letter[2:7]?

a. [1] "b" "c" "d" "e" "f" "g"


b. [1] "B" "C" "D" "E" "F" "G"
c. [1] "2" "3" "4" "5" "6" "7"
d. Error...

4. Which one of the following is the correct outcome of the command LETTERS[15:10] ?

a. [1] "o" "n" "m" "l" "k" "j"

b. [1] "O" "N" "M" "L" "K" "J"

c. [1] "J" "K" "L" "M" "N" "O"

d. [1] "j" "k" "l" "m" "n" "o"

5. Which one of the following is the correct outcome of the command rep(5:9,3)?

a. [1] 5 5 5 6 6 6 7 7 7 8 8 8 9 9 9

b. [1] 5 6 6 7 7 7 8 8 8 8 9 9 9 9 9

c. [1] 5 6 7 8 9 5 6 7 8 9 5 6 7 8 9

d. [1] 9 8 7 6 5 9 8 7 6 5 9 8 7 6 5

2
6. Which one of the following is the correct outcome of the command

rep(50:46, times=4) ?

a. [1] 50 49 48 47 46 50 49 48 47 46 50 49 48 47 46 50 49 48 47 46

b. [1] 46 47 48 49 50 46 47 48 49 50 46 47 48 49 50 46 47 48 49 50

c. [1] 50 50 50 50 49 49 49 49 48 48 48 48 47 47 47 47 46 46 46 46

d. [1] 46 46 46 46 47 47 47 47 48 48 48 48 49 49 49 49 50 50 50 50

7. Which one of the following is the correct outcome of the command rep(35:40,
each=4) ?

a. [1] 35 36 37 38 39 40 35 36 37 38 39 40 35 36 37 38 39 40 35 36
37 38 39 40

b. [1] 35 35 35 35 36 36 36 36 37 37 37 37 38 38 38 38 39 39 39 39
40 40 40 40

c. [1] 40 40 40 40 39 39 39 39 38 38 38 38 37 37 37 37 36 36 36 36
35 35 35 35

d. [1] 40 39 38 37 36 35 40 39 38 37 36 35 40 39 38 37 36 35 40 39
38 37 36 35

3
8. Which one of the following is the correct outcome of the commands

x = matrix(nrow=3, ncol=3, data=1:9, byrow=F)

rep(x, each=2) ?

a. [1] 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 1

b. [1] 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9

c. [1] 9 8 7 6 5 4 3 2 1 9 8 7 6 5 4 3 2 1

d. [1] 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9

9. Which one of the following is the correct outcome of the command rep(c("CLASS1",
" CLASS2", " CLASS3"), each=3) ?

a. [1] "CLASS1" "CLASS1" "CLASS1" " CLASS2" " CLASS2" " CLASS2"
" CLASS3" " CLASS3" " CLASS3"

b. [1] "CLASS1" "CLASS2" "CLASS3" " CLASS1" " CLASS2" " CLASS3"
" CLASS1" " CLASS2" " CLASS3"

c. [1] CLASS 1 2 3 CLASS 1 2 3

d. [1] CLASS 1 1 CLASS 2 2 CLASS 3 3

4
10. Which one of the following is the correct outcome of the command
sort(c(15,55,18,32,97,71,82,42,66), decreasing = FALSE)?

a. [1] 1 5 2 3 9 7 8 4 6

b. [1] 6 4 8 7 9 3 2 5 1

c. [1] 15 18 32 42 55 66 71 82 97

d. [1] 97 82 71 66 55 42 32 18 15

11. Which one of the following is the correct outcome of the command

sort(c(15,55,18,32,97,71,82,42,66), decreasing = TRUE) ?

a. [1] 1 5 2 3 9 7 8 4 6

b. [1] 6 4 8 7 9 3 2 5 1

c. [1] 15 18 32 42 55 66 71 82 97

d. [1] 97 82 71 66 55 42 32 18 15

12. Which one of the following is the correct outcome of the command
order(c(15,55,18,32,97,71,82,42,66), decreasing = FALSE) ?

a. [1] 15 18 32 42 55 66 71 82 97

b. [1] 97 82 71 66 55 42 32 18 15

c. [1]1 3 4 8 2 9 6 7 5

d. [1] 5 7 6 9 2 8 4 3 1

5
13. Which one of the following is the correct outcome of the command
mode(c(10, 20, "30", 80+90, "70+90", 16.7, 10*5))?
a. character

b. numeric

c. list

d. data frame

14. Which one of the following is the correct outcome of the command x[[3]] where,
x =list (c("class1", "class2", "class3"), seq(from=50, to=57),
rep(28:30, each=3)) ?
a. [1] "class1" "class2" "class3"

b. [1] 50 51 52 53 54 55 56 57

c. [1] 28 28 28 29 2929 30 30 30

d. [1] "class3" 52 28

15. Which one of the following is the correct outcome of the command x[[2]][2]
where x =list (c("class1", "class2", "class3"), seq(from=50, to=57),
rep(28:30, each=3)) gives an output as
a. [1] "class2"

b. [1] 51

c. [1] 29

d. [1] 50 51 52 53 54 55 56 57

6
16. Which one of the following is the correct outcome of the command x[2][2] where

x =list (c("class1", "class2", "class3"), seq(from=50, to=57),


rep(28:30, each=3)) ?
a. "class2"

b. 51

c. 29

d. "NULL"

17. Which one of the following is the correct outcome of the command x[3] where
x =list (c("class1", "class2", "class3"), seq(from=50, to=57),
rep(28:30, each=3)) ?
a. [1] "class3"

b. [1] 28 28 28 29 29 29 30 30 30

c. [1] 52

d. [1] 50 51 52 53 54 55 56 57

18. Consider the list z = list(x1 = "class", x2 = 20:25). Which one of the
following is the correct outcome of the command z["x2"] ?

a. [1] "class"
b. [1] "20:25"
c. [1] 25 24 23 22 21 20
d. [1] 20 21 22 23 24 25

7
MOOC Course - Foundations of R Software

Answers of Assignment 7
1. a

2. c

3. d

4. b

5. c

6. a

7. b

8. b

9. a

10. c

11. d

12. c

13. a

14. c

15. b

16. d

17. b

18. d

8
MOOC Course - Foundations of R Software

July 2022

Assignment 8

1. Consider the list x=list("UP", "MP", "J&K", "Bihar", 20, 40, "60+40").
Which one of the following is the correct outcome of the command append(x, 200) ?

a.
[[1]]
[1] 200

[[2]]
[1] "UP"

[[3]]
[1] "MP"

[[4]]
[1] "J&K"

[[5]]
[1] "Bihar"

[[6]]
[1] 20

[[7]]
[1] 40

[[8]]
[1] "60+40"

1
b.
[[1]]
[1] "200"

[[2]]
[1] "UP"

[[3]]
[1] "MP"

[[4]]
[1] "J&K"

[[5]]
[1] "Bihar"

[[6]]
[1] 20

[[7]]
[1] 40

[[8]]
[1] 100

c.
[[1]]
[1] "UP"

[[2]]
[1] "MP"

[[3]]
[1] "J&K"

[[4]]
[1] "Bihar"

[[5]]
[1] 20

[[6]]
[1] 40

[[7]]
[1] "60+40"

[[8]]
[1] 200

2
d.

[[1]]
[1] "UP"

[[2]]
[1] "MP"

[[3]]
[1] "J&K"

[[4]]
[1] "Bihar"

[[5]]
[1] 40

[[6]]
[1] 20

[[7]]
[1] "60+40"

[[8]]
[1] "200"

3
2. Consider the list x=list("UP", "MP", "J&K", "Bihar", 20, 40, "60+40").
Which one of the following is the correct outcome of the command append(x, 200,
after =2) ?

a.
[[1]]
[1] "UP"

[[2]]
[1] "MP"

[[3]]
[1] 200

[[4]]
[1] "J&K"

[[5]]
[1] "Bihar"

[[6]]
[1] 20

[[7]]
[1] 40

[[8]]
[1] "60+40"

b.
[[1]]
[1] "UP"

[[2]]
[1] "MP"

[[3]]
[1] "200"

[[4]]
[1] "J&K"

[[5]]
[1] "Bihar"

[[6]]

4
[1] 20

[[7]]
[1] 20

[[8]]
[1] "60+40"

c.
[[1]]
[1] "UP"

[[2]]
[1] "MP"

[[3]]
[1] "J&K"

[[4]]
[1] "Bihar"

[[5]]
[1] 20

[[6]]
[1] 40

[[7]]
[1] "60+40"

[[8]]
[1] 200

d.

[[1]]
[1] "UP"

[[2]]
[1] "MP"

[[3]]
[1] "J&K"

[[4]]
[1] "Bihar"

5
[[5]]
[1] 20

[[6]]
[1] 40

[[7]]
[1] "60+40"

[[8]]
[1] "200"

3. Consider the list x=list("UP", "MP", "J&K", "Bihar", 20, 40, "60+40").
Which one of the following is the correct outcome of the command x[2:3] ?

a.
[[1]]

[[6]]
[1] 20

[[7]]
[1] 40

b.
[[1]]
[1] "MP"

[[2]]
[1] "J&K"

6
c.
[2] "MP" [3] "J&K"

d.
[[1]]
[1] "UP"

[[2]]
[1] "MP"

[[3]]
[1] "J&K"

[[4]]
[1] "Bihar"

[[5]]
[1] 20

[[6]]
[1] 40

[[7]]
[1] "60+40"

[[8]]
[1] "200"

4. Consider the list z = list(x1 = "class", x2 = 20:25). Which of the


following is the correct command to change the element x2 by y2?

a. names(z)[2]= y2
b. names(z)[2]= "y2"
c. names(y)[2]= "z2"
d. names(y)[2]= z2

7
5. Which one of the following is the correct outcome of the command
factor(c(10,10,20,20,30,30)) ?

a.
[1] 10 10 20 20 30 30
Levels: 10 20 30

b.
[1] 10 20 30
Levels: 10 20 30

c.
[1] 10 20 30
Levels: 10 10 20 20 30 30

d.
[1] 10 10 20 20 30 30
Levels: 10 10 20 20 30 30

6. Which one of the following is the correct outcome of the following commands?
data = c(4,4,2,2,6,6,9)
factor(data)
levels(data) = c('A','B','C','D')
data
a.
[1] 4 4 2 2 6 6 9
attr(,"levels")
[1] "A" "B" "C" "D"

b.

[1] 4 2 6 9
attr(,"levels")

8
[1] "A" "B" "C" "D"

c.
[1] A A B B C C D
Levels: 1 2 3

d.
[1] B A C D
attr(,"levels")
[1] "2" "4" "6" "9"

7. Which one of the following is the correct outcome of the command

x = factor(c(10,20,20,50,10,20,10,50,60,60),
levels=c(10,20,50,60),ordered=TRUE) ?

a.

[1] 10 < 20 < 50 < 60


Levels: 10 20 20 50 10 20 10 50 60 60

b.

[1] 10 20 50 60
Levels: 10 20 20 50 10 20 10 50 60 60

c.

[1] 10 20 20 50 10 20 10 50 60 60
Levels: 10 < 20 < 50 < 60

d.
[1] 10 20 20 50 10 20 10 50 60 60
Levels: 1 < 2 < 5 < 6

9
8. Which one is the correct outcome of the command
factor( c(rep("head",3), rep("tale", 4))) ?
a.
[1] head tale
Levels: head head head tale tale tale tale

b.
[1] head head head head tale tale tale
Levels: head tale

c.
[1] tale tale tale tale head head head
Levels: head tale

d.
[1] head head head tale tale tale tale
Levels: head tale

10
9. Which one of the following is the correct outcome of the command
unclass(factor( c("high school", "graduation", "post graduation", "
graduation", "high school", "post graduation", "high school", "post
graduation"), levels=c("high school", "graduation", "post graduati
on") )) ?

a.
[1] 1 2 3 2 1 3 1 3
attr(,"levels")
[1] "high school" "graduation" "post graduation"

b.
[1] 3 2 1 2 3 1 3 1
attr(,"levels")
[1] "post graduation" "graduation" "high school"

c.

[1] 1 2 3
attr(,"levels")
[1] "high school" "graduation" "post graduation"

d.
[1] 3 2 1
attr(,"levels")
[1] "post graduation" "graduation" "high school"

11
10. Which one of the following is the correct outcome of the command

as.factor(c(1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5) ) ?
a.
[1] 1 2 3 4 5
Levels: 1 2 3 4 5

b.
[1] 5 5 5 4 4 3 3 3 2 2 1
Levels: 5 4 3 2 1

c.
[1] 1 2 2 3 3 3 4 4 5 5 5
Levels: 1 2 3 4 5

d.
[1] 1 2 2 3 3 3 4 4 5 5 5
Levels: 5 4 3 2 1

11. Which one of the following is the correct outcome of the command
print(2/3,digits=6) ?

a. [1] 0.66667

b. [1] 0.6667

c. [1] 0.666667

d. [1] 0.667

12
12. Which one of the following is the correct outcome of the command

print("The average marks of the class is", (40+10)/3, "in first yea
r.", digits=5) ?
a. [1] "The average marks of the class is" 16.667 "in first year."

b. [1] The average marks of the class is 16.667 in first year.

c. [1] "The average marks of the class is"

d. [1] The average marks of the class is 16.66667 in first year.

13. Which one of the following is the correct outcome of the command
print("My house has"); print(2+4); print("rooms.") ?
a. [1] "My house has" 6 "rooms."
b.
[1] "My house has"
[1] 6
[1] "rooms."
c. [1] "My house has" 2+4 "rooms."
d. [1] My house has 6 rooms.

14. Which one of the following is the correct outcome of the command
format(12345678910, big.mark = "*") ?

a. "1*2*3*4*5*6*7*8*9*1*0"
b. "123*45*678*910"
c. "12*34*56*78*91*0"
d. "12*345*678*910"

13
15. Which one of the following is the correct outcome of the command
print( format( 2.5, digits=6, nsmall=10 ) ) ?

a. "2.5"
b. "2.5000"
c. "2.5000000000"
d. "2.500000"

14
MOOC Course - Foundations of R Software

Answers of Assignment 8
1. c

2. a

3. b

4. b

5. a

6. a

7. c

8. d

9. a

10. c

11. c

12. c

13. b

14. d

15. c

15
MOOC Course - Foundations of R Software
July 2022
Assignment 9

1. Let x <- 'Indian Institute of Technology Kanpur!\n' then which


one of the following are the respective correct outcome of the commands print(x)
and cat(x)?

a.
[1] Indian Institute of Technology Kanpur!\n
and
[1] Indian Institute of Technology Kanpur!\n

b.
[1] "Indian Institute of Technology Kanpur!"
and
Indian Institute of Technology Kanpur!\n

c.
[1] "Indian Institute of Technology Kanpur!"
and
Indian Institute of Technology Kanpur!\n

d.
[1] "Indian Institute of Technology Kanpur!\n"
and
Indian Institute of Technology Kanpur!
2. Which one of the following is the correct outcome of the command
print(paste("R course has", 10* 2:4, "students"))?
a. [1] "R course has" 10* 2 "students" "R course has" 10* 3 "
students" "R course has" 10* 4 "students"

b. [1] "R course has 20 students" "R course has 30 students" "
R course has 40 students"

c. [1] "R course has" 10*2 10*3 10*4 "students"

d. [1] R course has 20 students R course has 30 students R c


ourse has 40 students

3. Which one of the following is the correct outcome of the commands


x <- 36
y <- 27
cat("The square root of", "x", "is", sqrt(x), "and the cube
root of y is", y^(1/3), "!\n") ?
a. The square root of 36 is 6 and the cube root of 27 is 9 !

b. The square root of x is sqrt(x) and the cube root of y is y^


(1/3) !

c. "The square root of" "x" "is" 6 " and the cube root of y is"
3 !\n

d. The square root of x is 6 and the cube root of y is 3 !


4. Which one of the following is the correct outcome of the command
x <- 7
cat("The approximate value of square root of", x, "is", format(
sqrt(x),digits=3),"\n") ?

a. "The approximate value of square root of 7 is 2.65"


b. "The approximate value of square root of x is 2.65"
c. The approximate value of square root of 7 is 2.65

d. The approximate value of square root of x is 2.65

5. Which one of the following is the correct outcome of the command


paste("The age of 3 students are", c("18 years", "19 years", "
20 years"), collapse=", and ") ?

a. [1] "The age of 3 students are 18 years, 19 years and 20 year


s"

b. [1] "The age of 3 students are 18 years, and The age of 3 stu
dents are 19 years, and The age of 3 students are 20 years"

c. [1] "The age of 3 students are 18 years, and 19 years, and 20


years"

d. [1] "The age of 3 students are 18, 19 and 20 years"


6. Which one of the following is the correct outcome of the command
paste("Students in class 1, 2 and 3 are", 50:52, sep=":") ?

a.
[1] "Students in class 1 are:50" "Students in class 2 are:51" "

Students in class 3 are:52"

b.

[1] "Students in class 1, 2 and 3 are:50:52" "Students in class

1, 2 and 3 are:50:52" "Students in class 1, 2 and 3 are:50:52"

c.

[1] "Students in class 1, 2 and 3 are:50 Students in class 1, 2

and 3 are:51 Students in class 1, 2 and 3 are:52"

d.

[1] "Students in class 1, 2 and 3 are:50" "Students in class 1,

2 and 3 are:51" "Students in class 1, 2 and 3 are:52"


7. Which one of the following is the correct outcome of the command
paste("Total number of pages in books are", 200:202, sep="+", c
ollapse="") ?

a.
[1] "Total number of pages in books are+200Total number of page
s in books are+201Total number of pages in books are+202"
b.
[1] "Total number of pages in books are+200+201+202"
c.
[1] "Total number of pages in books are 603"
d.
[1] "Total number of pages in books are 200" + "Total number o
f pages in books are 201" + "Total number of pages in books are
202"
8. Which one of the following is the correct outcome of y where
y=strsplit("Landlord of House Number 100::Landlord of House Num
ber 200::Landlord of House Number 300","::") ?
a.
[[1]]
[1] " Landlord of House Number 100:200::300"

b.
[[1]]
[1]
Landlord of House Number 100, Landlord of House Number 200, Lan
dlord of House Number 300,

c.
[[1]]
[1] "Landlord of House Number 100" "Landlord of House Number 20
0" "Landlord of House Number 300"

d.
[[1]]
[1] "Landlord of House Number 100"::"Landlord of House Number 2
00"::"Landlord of House Number 300"

9. Let
y=strsplit("Landlord of House Number 100::Landlord of House Num
ber 200::Landlord of House Number 300","::")
Which one of the following is the correct command to get the outcome of y as "Lan
dlord of House Number 300" ?
a. y[1][3]

b. y[3][1]

c. y[[1]][3]

d. [[3]][1]
10. Which one of the following is the correct outcome of the command
nchar("NPTEL - National Programme on Technology Enhanced Learni
ng- is a joint initiative of the IITs and IISc.") ?
a. [1] 99
b. [1] 100
c. [1] 101
d. [1] 103

11. Which one of the following is the correct outcome of the command
nzchar("NPTEL - National Programme on Technology Enhanced Learn
ing- is a joint initiative of the IITs and IISc.") ?
a. TRUE
b. FALSE
c. 103
d. 101

12. Which one of the following is the correct outcome of nzchar(x) where
x=c("NPTEL - National Programme on Technology Enhanced
Learning-", "is a joint initiative of the", "IITs and IISc.")?
a. TRUE
b. FALSE
c. FALSE FALSE FALSE
d. TRUE TRUE TRUE
13. Which one of the following is the correct outcome of the command tolower("
InDIan InStItUtE Of TEchNOloGY") ?
a. [1] "Indian Institute Of Technology")

b. [1] "indian institute of technology"

c. [1] "iNdiAN iNsTiTuTe oF teCHnoLOgy")

d. [1] "TEchNOloGY Of InStItUtE InDIan ")

14. Which one of the following is the correct outcome of the command toupper("
Institute Of National Importance in India") ?
a. [1] "institute of national importance in india"

b. [1] "iNSTITUTE oF nATIONAL iMPORTANCE IN iNDIA"

c. [1] "INSTITUTE OF NATIONAL IMPORTANCE IN INDIA"

d. [1] "Institute Of National Importance in India"


MOOC Course - Foundations of R Software
Answers of Assignment 9

1. d
2. b
3. d
4. c
5. b
6. d
7. a
8. c
9. c
10. d
11. a
12. d
13. b
14. c
MOOC Course - Foundations of R Software
July 2022
Assignment 10

1. Which one of the following is the correct outcome of the command


sub("8", "12", "Foundations of R Software Course will be of 12
weeks duration" ) ?
a. [1] "Foundations of R Software Course will be of 8 weeks dur
ation"

b. [1] "Foundations of R Software Course will be of 12 weeks du


ration"

c. [1] "Foundations of R Software Course will be of 8-12 wee


ks duration"

d. [1] "Foundations of R Software Course will be of 8, 12 wee


ks duration"

2. Which one of the following is the correct outcome of the command


gsub("Students in mathematics course", "Students in statistics
course", "mathematics - 250. statistics - 300") ?

a. [1] "mathematics - 250. statistics - 300"

b. [1] "Students in mathematics course - 250." " Students in


mathematics course - 300"

c. [1] "Students in statistics course - 250." " Students in


statistics course - 300"

d. [1] "Students in statistics course - 250." "mathematics


Course - 300"
3. Which one of the following is the correct outcome of the command
grep("cdab", c("cdabc", "cdef", "cbcdaba", "adcdaba", "cdabcdab
" )) ?

a. [1] "cdabc" "cbcdaba" "adcdaba" "cdabcdab"

b. [1] "cdef"

c. [1] 1 3 4 5

d. [1] 2

4. Which one of the following is the correct outcome of the command


grep("[m-r]", letters) ?
a. [1] m-n-o-p-q-r

b. [1] m n o p q r

c. [1] 13–14–15–16-17-18

d. [1] 13 14 15 16 17 18

5. Which one of the following is the correct outcome of the command


grepl("Students",x) where
x=c("Students in mathematics course", "Students in statistics
course", "mathematics - 250. statistics - 300") ?

a. TRUE TRUE FALSE

b. TRUE

c. FALSE

d. FALSE FALSE TRUE


6. Which one of the following are the respective correct commands to obtain the
names of columns and rows in a data frame mtcars ?
a. colnames(mtcars) and rownames(mtcars)
b. colname(mtcars) and rowname(mtcars)
c. coln(mtcars) and rown(mtcars)
d. cnames(mtcars) and rnames(mtcars)

7. Which one of the following is the correct command to obtain the dimension, name,
and type of each variable in a data frame mtcars ?
a. string(mtcars)
b. strname(mtcars)
c. str(mtcars)
d. stringname(mtcars)

8. Which one of the following is the correct command to extract the variable gear fro
m a data frame mtcars ?
a. gear$mtcars
b. name(mtcars$gear)
c. name(gear$mtcars)
d. mtcars$gear

9. Which one of the following is the correct command to extract the first five data point
s contained in the variable mpg from a data frame mtcars?
a. mpg$mtcars[1:5]
b. mtcars$mpg[1:5]
c. mtcars$mpg[1,5]
d. [mtcars,suzuki](1,5)
Answer Questions 10-12 on the basis of the following information:
Consider the data frame painters in the library MASS. Use command library(M
ASS) to load the library MASS and use the command attach(painters) to attac
h the database painters.

10. Which one of the following is respectively the correct command to draw informatio
n on those painters who have used the "Colour" coded as 6 and are from "School" F fr
om the data frame painters and what is the corresponding outcome?

a.
subset(painters, Colour==6 & School==F)
and
Composition Drawing Colour Expression School
Pourbus 4 15 6 6 F
Van Leyden 8 6 6 4 F

b.
subset(painters, Colour=6 & School=F)
and
Composition Drawing Colour Expression School
Pourbus 4 15 6 6 F
Van Leyden 8 6 6 4 F

c.
subset(painters, Colour=='6' & School=='F')
and
Composition Drawing Colour Expression School
Pourbus 4 15 6 6 F
Van Leyden 8 6 6 4 F

d.
subset(painters, Colour=='6' and School=='F')
and
Composition Drawing Colour Expression
Pourbus 4 15 6 6
Van Leyden 8 6 6 4
11. Which one of the following is respectively the correct command to draw the inform
ation on those painters who have used the "Composition" as 15 and "Expression" is
more than 9 and what is the output from the data frame painters?

a.
subset(painters, Composition =='15' & Expression > 9)
and
Composition Drawing Colour Expression School
Perino del Vaga 15 16 7 6 A
Tintoretto 15 14 16 4 D
Veronese 15 10 16 3 D
Teniers 15 12 13 6 G

b.
subset(painters, Composition =='15' & Expression > 9)
and
Composition Drawing Colour Expression School
Da Vinci 15 16 4 14 A
Guilio Romano 15 16 4 14 A
Primaticcio 15 14 7 10 B
Vanius 15 15 12 13 C
Domenichino 15 17 9 17 E
The Carraci 15 17 13 13 E
Rembrandt 15 6 17 12 G
Van Dyck 15 10 17 13 G
Le Suer 15 15 4 15 H
Poussin 15 17 6 15 H

c.
subset(painters, Composition =='15' & Expression > '9')
and
Composition Drawing Colour Expression School
Da Vinci 15 16 4 14 A
Guilio Romano 15 16 4 14 A
Primaticcio 15 14 7 10 B
Vanius 15 15 12 13 C
Domenichino 15 17 9 17 E
The Carraci 15 17 13 13 E
Rembrandt 15 6 17 12 G
Van Dyck 15 10 17 13 G
Le Suer 15 15 4 15 H
Poussin 15 17 6 15 H
d.
subset(painters, Composition =15 & Expression > 9)
and
Composition Drawing Colour Expression School
Da Udine 10 8 16 3 A
Da Vinci 15 16 4 14 A
Del Piombo 8 13 16 7 A
Del Sarto 12 16 9 8 A
Fr. Penni 0 15 8 0 A
Guilio Romano 15 16 4 14 A
Michelangelo 8 17 4 8 A
Perino del Vaga 15 16 7 6 A
Perugino 4 12 10 4 A
Raphael 17 18 12 18 A
F. Zucarro 10 13 8 8 B
Fr. Salviata 13 15 8 8 B
Parmigiano 10 15 6 6 B
Primaticcio 15 14 7 10 B
T. Zucarro 13 14 10 9 B
Volterra 12 15 5 8 B
Barocci 14 15 6 10 C
Cortona 16 14 12 6 C
Josepin 10 10 6 2 C
L. Jordaens 13 12 9 6 C
Testa 11 15 0 6 C
Vanius 15 15 12 13 C
Bassano 6 8 17 0 D
Bellini 4 6 14 0 D
Giorgione 8 9 18 4 D
Murillo 6 8 15 4 D
Palma Giovane 12 9 14 6 D
Palma Vecchio 5 6 16 0 D
Pordenone 8 14 17 5 D
Tintoretto 15 14 16 4 D
Titian 12 15 18 6 D
Veronese 15 10 16 3 D
Albani 14 14 10 6 E
Caravaggio 6 6 16 0 E
Corregio 13 13 15 12 E
Domenichino 15 17 9 17 E
Guercino 18 10 10 4 E
Lanfranco 14 13 10 5 E
The Carraci 15 17 13 13 E
Durer 8 10 10 8 F
Holbein 9 10 16 13 F
Pourbus 4 15 6 6 F
Van Leyden 8 6 6 4 F
Diepenbeck 11 10 14 6 G
J. Jordaens 10 8 16 6 G
Otho Venius 13 14 10 10 G
Rembrandt 15 6 17 12 G
Rubens 18 13 17 17 G
Teniers 15 12 13 6 G
Van Dyck 15 10 17 13 G
Bourdon 10 8 8 4 H
Le Brun 16 16 8 16 H
Le Suer 15 15 4 15 H
Poussin 15 17 6 15 H
12. Which one of the following are respectively the correct commands to draw the info
rmation and output on those painters who have used the "Colour" coded as 4 , "Scho
ol" as A when information on the variables "Drawing" and "Expression" is removed fro
m the data frame painters and its corresponding outcome?

a.
subset(painters, School=A & Colour=, select=c(-2,-4))
and
Composition Colour School
Da Vinci 15 4 A
Guilio Romano 15 4 A
Michelangelo 8 4 A

b.
subset(painters, School=="A" & Colour=="4", select=c(-2,-4))
and
Composition Drawing Colour Expression School
Da Vinci 15 16 4 14 A
Guilio Romano 15 16 4 14 A
Michelangelo 8 17 4 8 A

c.
subset(painters, School=A & Colour=4, select=c(-2,-4))
and
Composition Drawing Colour Expression School
Da Vinci 15 16 4 14 A
Guilio Romano 15 16 4 14 A
Michelangelo 8 17 4 8 A

d.
subset(painters, School=="A" & Colour=="4", select=c(-2,-4))
and
Composition Colour School
Da Vinci 15 4 A
Guilio Romano 15 4 A
Michelangelo 8 4 A
13. Suppose x = c("Germany", "India", "USA") and y = c(10, 20, 30)
then which of the following is the correct outcome of the command rbind(x,y)when
executed in R console?

A.

[,1] [,2] [,3]


x "Germany" "India" "USA"
y "10" "20" "30"

B.

x y
[1,] "Germany" "10"
[2,] "India" "20"
[3,] "USA" "30"

C.

[,1] [,2] [,3]


y "10" "20" "30"
x "Germany" "India" "USA"

D.

y x
[1,] "10" "Germany"
[2,] "20" "India"
[3,] "30" "USA"
14. Suppose x = c("Germany", "India", "USA") and y = c(10, 20, 30)
then which of the following is the correct outcome of the command cbind(x,y)when
executed in R console?

A.

[,1] [,2] [,3]


x "Germany" "India" "USA"
y "10" "20" "30"

B.

[,1] [,2] [,3]


y "10" "20" "30"
x "Germany" "India" "USA"

C.

x y
[1,] "Germany" "10"
[2,] "India" "20"
[3,] "USA" "30"

D.

y x
[1,] "10" "Germany"
[2,] "20" "India"
[3,] "30" "USA"
MOOC Course - Foundations of R Software
Answers of Assignment 10

1. b

2. a

3. c

4. d

5. a

6. a

7. c

8. d

9. b

10. c

11. b

12. d

13. a

14. c
MOOC Course - Foundations of R Software
July 2022
Assignment 11

1. A comma separated value data file named as course.csv having header c


an be correctly read in R by which of the following command?
a. readcsv("course.csv", header= TRUE)
b. read.csv("course.csv", header=FALSE)
c. csvread(course.csv, header=FALSE)
d. read.csv("course.csv", header= TRUE)

2. A tabular data file named as course1.txt where the values are separated b
y blank space and having header can be correctly read in R by which of the f
ollowing command?
a. read.table("course1.txt", header= TRUE, sep = " ")
b. read.txt("course1.txt", header=FALSE, sep = " ")
c. tabularread(course1.txt, header=FALSE, sep = " ")
d. read.table(course1.txt, header= TRUE, sep = )

3. A spreadsheet created in MS-Excel software is named as marks.xlsx . The


sheet number 2 of this file can be correctly read in R by which of the following comm
and?
a. read_excel("marks.xlsx", sheet=2)
b. read.excel("marks.xlsx", sheetIndex=2)
c. Read_excel("marks.xlsx", sheet=2)
d. read.excel(marks.xlsx, sheetIndex=2)
4. A spreadsheet created in MS-Excel software is named as marks.xlsx . One
of the sheets in this file whose name is Physics can be read in R by which of the f
ollowing command?
a. read.excel("marks.xlsx", sheetName="Physics")
b. read.excel("marks.xlsx", sheet="Physics")
c. read_excel("marks.xlsx", sheet="Physics")
d. read_excel("marks.xlsx", name="Physics")

5. Suppose two dice are rolled 10 times and following is the sum of the numbers on
the upper faces of the dice: 6,3,12,12,7,7,7,6,3,2. Which one of the following is the
correct command to obtain the absolute frequencies of this data in R?

a. table(c(6,3,12,12,7,7,7,6,3,2))

b. table(6,3,12,12,7,7,7,6,3,2)

c. table(c(6,3,12,12,7,7,7,6,3,2))/length(c(6,3,12,12,7,7,7,6,3
,2))

d. table(6,3,12,12,7,7,7,6,3,2)/length(6,3,12,12,7,7,7,6,3,2)
6. Suppose two dice are rolled 20 times and the following are the sum of numbers
on the upper face: 8, 8, 7, 12, 2, 3, 5, 3, 4, 6, 7, 6, 5, 6, 6, 7, 4, 3, 2, 9, 9. Which one
of the following is the correct outcome of the following command in R?
table(c(8,8,7,12,2,3,5,3,4,6,7,6,5,6,6,7,4, 3,2,9))

a.
2 3 4 5 6 7 8 9 12
0.10 0.15 0.10 0.10 0.20 0.15 0.10 0.10 0.05

b.
2 3 4 5 6 7 8 9 12
1 1 1 1 1 1 1 2 1

c.
2 3 4 5 6 7 8 9 12
2 3 2 2 4 3 2 1 1

d.
2 3 2 2 4 3 2 1 1
2 3 4 5 6 7 8 9 12

7. Which one of the following is the correct command to obtain the 2nd , 5th, 7th and
9th deciles of a data vector x in R?

a. decile(x, probs=c(20%,50%,70%,90%))

b. decile(x, probs=(0.20,0.50,0.70,0.90))

c. quantile(x, probs=(20%,50%,70%,90%))

d. quantile(x, probs=c(0.20,0.50,0.70,0.90))
8. Which one of the following correctly specify the quantiles of a data vector marks
obtained as an outcome of the command quantile(marks, probs = seq(0,
1, 0.15)) in R?

a. 15th

b. 0th,15th,30th,45th,60th,75th,90th

c. 15th,30th,45th,60th,75th,90th

d. 15th,45th,90th

9. Suppose two dice are rolled 10 times and the following sum of the numbers on
the upper faces of the dice: 6,3,12,12,7,7,7,6,3,2. Which of the following command
in R is used to obtain the bar plot of this data based on relative frequencies?
a. barplot(6,3,12,12,7,7,7,6,3,2)/length(6,3,12,12,7,7,7,6,3,2)

b. barplot(table(6,3,12,12,7,7,7,6,3,2)/length(6,3,12,12,7,7,7,6,
3,2))

c. barplot(c(6,3,12,12,7,7,7,6,3,2))/length(c(6,3,12,12,7,7,7,6,3
,2)))

d. barplot(table(c(6,3,12,12,7,7,7,6,3,2))/length(c(6,3,12,12,7,7,
7,6,3,2)))
10. Suppose two dice are rolled 10 times and the following sum of the numbers on
the upper faces of the dice: 6,3,12,12,7,7,7,6,3,2. Which of the following command i
n R is used to obtain the bar plot of this data based on absolute frequencies having
the main title as “Sum of Numbers on Dice” and all the bars are filled in red colour?

a. barplot(table(c(6,3,12,12,7,7,7,6,3,2)), main="Sum of Numbers o


n Dice", col="red")

b. barplot((6,3,12,12,7,7,7,6,3,2), title="Sum of Numbers on Dice"


, col="red")

c. barplot(table(c(6,3,12,12,7,7,7,6,3,2)), main=Sum of Numbers o


n Dice, col=red)

d. barplot(table(c(6,3,12,12,7,7,7,6,3,2)), title=Sum of Numbers


on Dice, col=red)
MOOC Course - Foundations of R Software
Answers of Assignment 11

1. d
2. a
3. a
4. c
5. a
6. c
7. d
8. b
9. d
10. a

You might also like