You are on page 1of 106

Introduction to R Software

July 2019

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

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

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 option will provide the demonstration of the package lm.glm?

a. demo(lm.glm)

b. demo = lm.glm

c. help(demo = lm.glm)

d. demonstration("lm.glm")

4. Which of the following is the correct command to see a working example of the
package glm in R console?

a. example(glm)
b. ex(glm)
c. example[glm]
d. ex("glm")
1
5. What will be the outcome of the value of z when the following commands are
executed over the R console

x=28
y=x^4
z=y^2+x^5

a. 377891208704
b. 377819280704
c. 377819208704
d. 378719208704

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

35+6**5-63+48/63*74-4^5*24-87/16*12-3**8/52+76-47+20 ?
a. 16914.04
b. -16914.04
c. -16491.04
d. 16491.04

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

25**(-5)*3-18^(-4/5)/(84/42)+41^3+14-78*(-1/4)-8^(-6**7) ?

a. 68954.45
b. -68954.45
c. 87954.54
d. None of these

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


c(12,23,34,45)/c(11,22,2,4)*c(12,11,13,21)**c(4,2,2,2)-
5*c(21,21,32,15) ?

a. -22516.09 -21.50 2713.00 4886.25


b. 22516.09 21.50 2713.00 4886.25
c. 22516.09 21.50 -2713.00 -4886.25
d. Error:...

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

c(8,16,26,20)/c(32,43)- c(14,12,14,12)^c(3,2)
+c(12,14,18,16)/c(21,12)- c(13,18,12,14)*c(3,1)?

a. -2782.1786 160.4612 -2778.3304 156.2016


b. 2782.1786 -160.4612 -2778.3304 156.2016
c. -2782.1786 -160.4612 -2778.3304 -156.2016
d. -2782.1786 160.4612 -2778.3304 156.2016

3
10. Which one of the following commands will give a result without a warning?

a. c(12,13,15,7)^c(5,4) * c(12,3,14,5)**c(2,3,4,-5) -
c(249,130,276,438)/c(18,31,2) + 6
b. c(12,13,15,7)^c(5,4) * c(12,3,14,5)**c(2,3,4,-5) -
c(249,130,276,438)/c(18,31) + 6
c. c(12,13,15,7)^c(5,4,3) * c(12,3,14,5)**c(2,3,4,-5) -
c(249,130,276,438)/c(18,31) + 6
d. c(12,13,15,7)^c(5,4) * c(12,3,14,5)**c(2,3,4,-5) -
c(249,130,276,438)/c(18,31) + 6*c(2,4,1)

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

sqrt(c(12,13,15,7)^c(5,4) * c(12,3,14,5)**c(2,3,4,-5) +
c(29,10,276,438)/c(18,31) + 6)?

a. 5.985968e+03 8.781534e+02 1.707986e+05 4.571362e+00


b. 1.707986e+05 4.571362e+00 5.985968e+03 8.781534e+02
c. 5.985968e+03 4.571362e+00 8.781534e+02 1.707986e+05
d. Error:...

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

c(4,2,4,2)*-c(3,2,-3,-2)**c(-5,-2,1,2)*-c(3,4,-3,-3)+7 ?

a. 7.049383 9.000000 43.000000 17.000000


b. 7.049383 9.000000 43.000000 -17.000000
c. 7.049383 -9.000000 43.000000 -17.000000
d. -7.049383 9.000000 43.000000 -17.000000

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

c(15,16,25,82)%/%c(4,8) - c(464,624,324,224)%/%c(14,13,25,37)+
c(53,46,87,78)%%c(7,6,8,9) ?

a. -26 42 1 -10
b. 26 -42 -1 10
c. -26 -42 1 10
d. -26 42 -1 -10

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

sum(max(c(98,88,44,76)**c(-3,3))/min(c(149,444,22,378)^c(2
,3)) + prod(c(11,12,11,12)^c(2,3))/abs(c(-9,-24,-24,-59,26
)*min(c(4,-3,-2,6)))) ?
a. 5299364104
b. 3652994104
c. 3641045299
d. None of these

15. Which one of the following is the correct outcome of the command?
round(sum(c(1,2,1,2)^c(1,2))^2 * prod(c(1,2,1,2)^c(2,3)) -
ceiling(c(1,2,1,2)^c(1,2,3,7)*c(2,3)) + abs(c(-5,6,-7,8)^c(2,-
3)))

a. 6423 6447 6388 6016


b. 6423 6388 6447 6016
c. 6388 6447 6016 6423
d. 6016 6423 6388 6447

6
16. Which one of the following is the correct outcome of the command -
ceiling(c(15,16,17,18)^c(-2,-3))- floor(c(-5,-6,-7,-
8)^c(-2,-3))+ floor(c(12,13,14,15)**-c(-1,2)) -
round(c(15,16,17,18)^c(-2,3))?

a. -11 4096 -13 5832


b. 11 -4096 13 -5832
c. 11 4096 13 5832
d. -11 -4096 -13 -5832

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

ceiling(c(4,8,4,5)^-c(-3,-2) + sqrt(c(-36,16,-81,6)**c(2,-
3))*sqrt(c(12,13,14,15)^-c(2,3)) - round(c(14,17,18,9)*roun
d(c(17,19)))) ?
a. -171 -258 -236 -145
b. -171 258 -236 145
c. 171 258 236 145
d. -171 -258 236 -145

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

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

a. 1504 1482 1355 1484 1483


b. 1504 1483 1484 1482 1355
c. 1504 1484 1483 1482 1355
d. 1484 1483 1482 1355 1504

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

X1 <- c(243,125,218,124)

X2 <- sqrt(X1^3)+X1*6/X1^2/3-sqrt(X1)**(5/2)-abs(X1)

a. 2585.5854 854.5958 2163.0751 843.0344


b. 2585.5854 2163.0751 854.5958 843.0344
c. 2585.5854 854.5958 843.0344 2163.0751
d. 854.5958 2585.5854 2163.0751 843.0344

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

c(2,2,5,4)^c(-1,-2,3,3)/c(4,3,12,1)
- c(12,24,9,16)%/%c(3,-1)*c(-2,1,-3,1)
- min(c(20,10,14,25)^c(1,2))%/%max(c(6,1,2,5)^c(2,3))?

a. 8.12500 24.08333 19.41667 80.00000


b. 8.12500 24.08333 19.41667 80.00000
c. 8.12500 24.08333 19.41667 80.00000
d. 8.12500 24.08333 19.41667 80.00000

9
MOOC Course - Introduction to R Software

Answers of Assignment 1

1. c

2. d

3. a

4. a

5. c

6. b

7. a

8. b

9. c

10. b

11. a

12. b

13. c

14. c

15. b

16. b

17. a

18. c

19. a

20. b

10
MOOC Course - Introduction to R Software

July 2019

Assignment 2
1. Which one of the following is the correct specification to compute

y  exp( x5/2 )  x 4  50 x 2  6 x and what is its value for x = 2 ?

a. y<-function(x){sqrt(exp(x^(5/2)+x^4)+50*x^2)-6^x},
y= 50398.32
b. y<-function(x){sqrt(exp(x^(5/2)))+51*x^2-6^x}, y= 184.9188
c. y<-function(x)(sqrt(exp(x^(5/2))+x^4)+50*x^2-6^x),
y=181.3852
d. y<- function(x){sqrt(exp(x^(5/2))+x^4)+50*x^2-6^x},
y = 181.3852

2. Which one of the following is the correct outcome of z(4,8) of the function
specified as z=function(x,y){sqrt(x^2/y^3+log(x*y))+log(-(15*x^-
2+16*y^-3-20))-(x^3+y^4)^(7/4)} ?
a. -215427
b. -2154827
c. 2154827
d. 215427

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

 51 54 57 
 
x   52 55 58 
 53 56 59 
 
a. x=matrix(51:59,3,3,byrow=T)
b. x=mat(51:59,3,3, byrow=T)
c. x=matrix(51:59,3,3,byrow=F)
d. x=mat(51:59,3,3,byrow=F)

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

 25 31 47 
z  
 58 69 72 

a. z <- matrix(nrow=2, ncol=3, data=c(25,31,47,58,69,72),


byrow=T)
b. z <- matrix(nrow=2, ncol=3, data=c(25, 31,47,58,69,72),
byrow=F)
c. z <- matrix(nrow=2, ncol=3, data=(25,58,31,69,47,72) ,
byrow=T)
d. z <- matrix(nrow=3, ncol=2, data=(25,58,31,69,47,72) ,
byrow=T)

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

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

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


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

6. Which one of the following is the correct outcome of the command X[3,4] for
the matrix constituted by the commands X<-matrix(80:91,4,4,byrow=F)?

a. 81
b. 82
c. 83
d. 91

3
7. Which one of the following is the correct outcome of the commands dim(x) and
dim(y) for the matrices obtained by x<-matrix(301:350,25,2,byrow=T)
and y<-matrix(201:250,2,25,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.

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

x <- diag(6, nrow=2, ncol=2) ?

6 6
a. x   
0 6

0 6
b. x   
6 0

6 6
c. x 
6 6

6 0
d. x 
0 6

4
9. Which one of the following is the correct outcome of the command t(x) for

x<-matrix(nrow=3, ncol=2, data=40:45, byrow=T) ?

a.
[,1] [,2] [,3]
[1,] 40 42 44
[2,] 41 43 45

b.
[,1] [,2]
[1,] 40 41
[2,] 42 43
[3,] 44 45

c.
[,1] [,2]
[1,] 40 43
[2,] 41 44
[3,] 42 45

d.
[,1] [,2] [,3]
[1,] 40 41 42
[2,] 43 44 45

5
10. Which one of the following is the correct command to obtain the multiplication of
three matrices x, y and z of the same order?

a. x**y**z

b. x*%*y*%*z

c. x%*%y%*%z

d. x%**%y%**%z

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

 55 77   22 23 
two matrices x  and y    along with its correct answer?
 66 88   26 21 

a. x*y and its correct answer is


[,1] [,2]
[1,] 1210 1771
[2,] 1716 1848

b. x*%*y and its correct answer is


[,1] [,2]
[1,] 3212 2882
[2,] 3740 3366

c. x%*%y and its correct answer is


[,1] [,2]
[1,] 3212 2882
[2,] 3740 3366

d. x%%*%%y and its correct answer is


[,1] [,2]
[1,] 3212 2882
[2,] 3740 3366

6
12. Let x<- matrix(nrow=3, ncol=3, data=69:61, byrow=F) then which
one of the following is the correct outcome of 7*x ?

a.

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


[1,] 483 462 441
[2,] 476 455 434
[3,] 469 448 427

b.

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


[1,] 483 476 469
[2,] 462 455 448
[3,] 441 434 427

c.

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


[1,] 483 476 469
[2,] 441 434 427
[3,] 462 455 448

d.

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


[1,] 441 434 427
[2,] 483 476 469
[3,] 462 455 448

7
13. Which one of the following is the correct outcome of the addition of two matrices

 55 77   22 23 
x  and y    along with its correct answer?
 66 88   26 21 

a.
x + y
and its correct answer is
[,1] [,2]
[1,] 77 100
[2,] 92 109
b.
x %+% y
and its correct answer is
[,1] [,2]
[1,] 77 92
[2,] 100 109
c.
x %%+%% y
and its correct answer is

[,1] [,2]
[1,] 77 100
[2,] 92 109

d.
x %+%+ y
and its correct answer is

8
[,1] [,2]
[1,] 92 109
[2,] 77 100

14. Let x<- matrix(nrow=4, ncol=4, data=26:41, byrow=F) then which


one of the following is the correct outcome of 4%*%x + x%*%x?

a.
[,1] [,2] [,3] [,4]
[1,] 3644 3758 3872 3986
[2,] 4172 4302 4432 4562
[3,] 4700 4846 4992 5138
[4,] 5228 5390 5552 5714

b.
[,1] [,2] [,3] [,4]
[1,] 3644 4172 4700 5228
[2,] 3758 4302 4846 5390
[3,] 3872 4432 4992 5552
[4,] 3986 4562 5138 5714

c. Error...

d. None of these

9
15. 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(15,20,25,30,35,40,45,50,55),


byrow=T) ?

a. [1] 25 40 55
b. [1] 45 50 55
c. [1] 55 40 25
d. [1] 55 50 45

10
16. Which one of the following is the correct outcome of x[2:3,3:4] for the matrix
specified by x<- matrix(nrow=4, ncol=4, data=26:41, byrow=F)?

a.
[,1] [,2]
[1,] 35 36
[2,] 39 40

b.

[,1] [,2]
[1,] 35 39
[2,] 36 40

c.
[,1] [,2]
[1,] 39 40
[2,] 35 36

d.
[,1] [,2]
[1,] 39 35

11
[2,] 40 36

 28 38 
 
17. Which one of the following is the correct command to get the matrix  58 68 
 88 98 
 
from the matrix specified by
X<-matrix(nrow=4, ncol=3, data=c(18,28,38,48,58,68,78,88,98,
108,110,112), 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]

1 2 3
18. Which of the following is the correct command to create the matrix ( ) in
4 5 6
R?

12
a. matrix(nrow=2, ncol=3, data=c(1,2,3,4,5,6), byrow=T)
b. matrix(nrow=3, ncol=2, data=c(1,2,3,4,5,6), byrow=T)
c. matrix(nrow=2, ncol=3, data=c(1,2,3,4,5,6), byrow=F)
d. matrix(nrow=3, ncol=2, data=c(1,2,3,4,5,6), byrow=F)

19. 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 var(x)?
a. 1088.04

b. 4632.2

c. Error...

d. NA

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

(x > 12) || (x < 14) & (x < 14) && (x > 11)||(x == 12) when
x = 12 and when x = -12 ?

a. FALSE and FALSE respectively.

b. TRUE and FALSE respectively.

c. FALSE and TRUE respectively.

13
d. TRUE and TRUE respectively.

21. Suppose x = 10:16 then which one of the following is the correct outcome of
the command (x > 12) | (x < 15)?

a. TRUE TRUE TRUE TRUE TRUE TRUE TRUE

b. FALSE FALSE FALSE FALSE FALSE FALSE FALSE

c. TRUE TRUE FALSE FALSE FALSE FALSE TRUE

d. FALSE FALSE TRUE TRUE TRUE TRUE FALSE

22. Suppose x = 4:16 then which one of the following correctly specifies the
outcome of the following statement: x[(x > 3) & (x < 17)] and x[(x > 4)
|| (x < 17)] ?

a. are different for both as 4 5 6 7 8 9 and 10 11 12 13 14 15 16


respectively.

b. are the same for both as 4 5 6 7 8 9 10 11 12 13 14 15 16

14
c. are different for both as 10 11 12 13 14 15 16 and as 4 5 6 7 8 9
respectively.

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

23. Suppose x = 100:500 then which one of the following is the correct command
to know that which of the values in x are more than 300 and less than 400?

a. x[(x > 300) & (x < 400)]

b. (x > 400) & (x < 500)

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

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

24. Suppose x = 15:20, then which of the following is the correct outcome of the
command x[(x > 15) | (x < 19)]?

a. 15 16 17 18 19 20
b. 16 17 18
c. 15 19 20
d. FALSE TRUE TRUE TRUE FALSE FALSE

15
e.

 11 21 16 18 
 
 34 36 12 17 
25. If x   42 24 34 28  then which one of the following is the correct
 
 13 16 27 26 

command and its outcome for obtaining the inverse of the matrix x?

a.
solve(x) =
[,1] [,2] [,3] [,4]
[1,] -0.1595092 0.06524016 -0.01230735 0.08102649
[2,] 0.2760736 -0.08289690 0.05577585 -0.19699237
[3,] 0.5276074 -0.25707018 0.19643124 -0.40872363
[4,] -0.6380368 0.28535089 -0.23215622 0.54361814

b.
inv(x) =
[,1] [,2] [,3] [,4]
[1,] -0.1595092 0.06524016 -0.01230735 0.08102649
[2,] 0.2760736 -0.08289690 0.05577585 -0.19699237
[3,] 0.5276074 -0.25707018 0.19643124 -0.40872363
[4,] -0.6380368 0.28535089 -0.23215622 0.54361814

c.
inv(x) =
[,1] [,2] [,3] [,4]
[1,] -0.15950920 0.27607362 0.5276074 -0.6380368
[2,] 0.06524016 -0.08289690 -0.2570702 0.2853509
[3,] -0.01230735 0.05577585 0.1964312 -0.2321562
[4,] 0.08102649 -0.19699237 -0.4087236 0.5436181

d.

16
solve(x) =
[,1] [,2] [,3] [,4]
[1,] -0.15950920 0.27607362 0.5276074 -0.6380368
[2,] 0.06524016 -0.08289690 -0.2570702 0.2853509
[3,] -0.01230735 0.05577585 0.1964312 -0.2321562
[4,] 0.08102649 -0.19699237 -0.4087236 0.5436181

17
MOOC Course - Introduction to R Software

Answers of Assignment 2

1. d

2. b

3. c

4. a

5. c

6. b

7. a

8. d

9. b

10. c

11. c

12. a

13. a

14. c

15. a

16. b

17. b

18. a

19. d

20. b

21. a
18
22. b

23. a

24 . a

25. a

19
MOOC Course - Introduction to R Software

July 2019

Assignment 3

1. If x = 18 then which one of the following is the correct outcome of

y=if (x==20) {x <- 3*x^3+9} else {x <- 4*x^2-3*x+8} ?

a. 24009

b. 1250

c. 1878

d. Error:...

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


6 x  | min( x , x ) | if
5/2 3 4
x2
y
 2 exp( x )  x
 x2
3/2 3/4
if

a. if ( x <= 2 ) { y <- 6 * x^(5/2) - min(x^3,x^4) } else { y


<- 2 * exp(x^(3/2)) - sqrt(x^(3/4))}
b. if ( x <= 2 ) { y <- 6 * x^(5/2) – abs(min(x^3,x^4)) }
else { y <- 2 * exp(x^(3/2)) - sqrt(x^(3/4))}
c. if ( x <= 2 ) ( y <- 2 * exp(x^(3/2)) - sqrt(x^(3/4)))
else ( y <- 6 * x^(5/2) – abs(min(x^3,x^4)) )
d. if ( x <= 2 ) { y <- 2 * exp(x^(3/2)) - sqrt(x^(3/4))}
else { y <- 6 * x^(5/2) - min(x^3,x^4) }

2
3. Suppose x = c(8,3,16,6,24,9,32,12) then which one of the following is the
correct output of

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

a. [1] 18 16 19 22 13 160 240 320 22

b. [1] 240 19 320 22 18 13 160 16

c. [1] 13 160 240 320 18 16 19 22

d. [1] 18 13 160 16 240 19 320 22

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

for(i in 10:15) {print(1 + 3i - i^2)} ?

a.
[1] -69
[1] -87
[1] -107
[1] -129
[1] -153
[1] -179

b.
[1] -224+3i
[1] -195+3i
[1] -168+3i
[1] -143+3i
[1] -120+3i
[1] -99+3i

c.
[1] -99+3i
[1] -120+3i
[1] -143+3i
[1] -168+3i
[1] -195+3i
[1] -224+3i

d.
[1] -179
[1] -153
[1] -129
[1] -107
[1] -87
[1] -69

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

for(i in 2:5) {print(i - 2*i + 3*i**2)} ?

a.

[1] -7-2i
[1] -6-2i
[1] -5-2i
[1] -4-2i
b.

[1] 10
[1] 24
[1] 44
[1] 70
c.

[1] 2 - 2*2 + 3*2**2


[1] 3 - 2*3 + 3*3**2
[1] 4 - 2*4 + 3*4**2
[1] 5 - 2*5 + 3*5**2
d. Error...

5
6. Which one of the following is the correct outcome of the following commands about
while loop?

y <- 4
while (y < 10) {
print(c("R Course","through SWYAM is helpful."))
y = y + 2
print(c("R Course","through SWYAM is not helpful."))
y = y + 3
}

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

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

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

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


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

6
7. Which one of the following is the correct outcome of the following while loop?

x <- 2

while(x < 15) {x <- x^2-10; if (x == 20) break; print(x^2); }

a.

[1] 36
[1] 676

b.

[1] 36
[1] 36

c.

[1] 676
[1] 676

d.

[1] 36
[1] 676
[1] 36
[1] 676

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

abs(seq(-20,-25))?

a. [1] 20 21 22 23 24 25

b. [1] -20 -21 -22 -23 -24 -25

c. [1] 25 24 23 22 21 20

d. [1] -25 -24 -23 -22 -21 -20

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


sqrt(abs(seq(-20,20, by = 10))) ?

a. [1] 3.162278 4.472136 0.000000 4.472136 3.162278

b. [1] 4.472136 3.162278 0.000000 3.162278 4.472136

c. [1] 3.162278 3.162278 0.000000 4.472136 4.472136

d. [1] 4.472136 4.472136 0.000000 3.162278 3.162278

8
10. Which one of the following is the correct output of the command seq(10,-10,
by = -2)?

a. [1] -10 -8 -6 -4 -2 0 2 4 6 8 10

b. [1] -2 -4 -6 -8 -10 0 10 8 6 4 2

c. [1] 2 4 6 8 10 0 -2 -4 -6 -8 -10

d. [1] 10 8 6 4 2 0 -2 -4 -6 -8 -10

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] -91 -92 -93 -94 -95 -96 -97 -98 -99 -100

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

9
12. 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] 209 208 207 206 205 204 303 202 201 200

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

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

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

seq(to = 212, length = 12, by = 21) ?

a. [1] 107 128 149 170 191 212 86 65 44 23 2 -19

b. [1] 212 191 170 149 128 107 86 65 44 23 2 -19

c. [1] -19 2 23 44 65 86 107 128 149 170 191 212


d. [1] 2 19 23 44 65 86 107 128 149 170 191 212

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

seq(from = -10, length = 10, by = -3.5) ?

a. [1] -10.0 -6.5 -3.0 0.5 4.0 7.5 11.0 14.5 18.0 21.5

b. [1] -10.0 -13.5 -17.0 -20.5 -24.0 -27.5 -31.0 -34.5 -38.0 -41.5

c. [1] -10.0 -14.5 -19.0 -23.5 -28.0 -32.5 -37.0 -41.5 -46.0 -50.5

d. [1] -10.0 -5.5 -1.0 3.5 8.0 12.5 17.0 21.5 26.0 30.5

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

X <- c(98, 47, 17, 180, 9, 143, 234, 149, 29, 8)


Y <- seq(along = X) ?

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

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

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

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

11
16. Which one of the following is the correct output of Y[X[4]] and Y[X[9]] for
the command

Y <- c(98, 47, 17, 180, 9, 143, 234, 149, 29, 8)

X <- c(5, 10, 7, 1, 4, 6, 8, 3, 2, 9) ?

a. 180 and 2 respectively.

b. 1 and 149 respectively.

c. 47 and 98 respectively.

d. 98 and 47 respectively.

17. Which one of the following is the correct command to generate a sequence of
three yearly dates 1-March-2017, 1- March -2018 and 1- March -2019?

a. seq(as.Date("2017-03-01"), as.Date("2019-03-01"), by =
"years")

b. seq(as.date("2017-03-01"), as.date("2019-03-01"),

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

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

d. seq(As.Date("2017-03-01"), As.Date("2019-03-01"), by =
"years")

12
18. Which one of the following is the correct command to generate the dates of 6
consecutive months starting from 15 June 2017?

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

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

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

d. seq(as.Date("2017-06-15") to as.Date("2017-08-15") by = "30")

19. Which one of the following is the correct outcome of the command
letter[12:17] ?

a. [1] "l" "m" "n" "o" "p" "q"


b. [1] "L" "M" "N" "O" "P" "Q"
c. [1] "12" "13" "14" "15" "16" "17"
d. Error...

13
20. Which one of the following is the correct outcome of the command
LETTERS[25:15] ?

a. [1] "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y"

b. [1] "Y" "X" "W" "V" "U" "T" "S" "R" "Q" "P" "O"

c. [1] "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y"

d. [1] "y" "x" "w" "v" "u" "t" "s" "r" "q" "p" "o"

21. Which one of the following is the correct outcome of the command rep(15:18,4)?

a. [1] 15 15 15 15 16 16 16 16 17 17 17 17 18 18 18

b. [1] 15 16 16 17 17 17 18 18 18 18

c. [1] 15 16 17 18 15 16 17 18 15 16 17 18 15 16 17 18

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

14
22. Which one of the following is the correct outcome of the command

rep(15:11, times=3) ?

a. [1] 15 14 13 12 11 15 14 13 12 11 15 14 13 12 11

b. [1] 15 15 15 14 14 14 13 13 13 12 12 12 11 11 11

c. [1] 11 11 11 12 12 12 13 13 13 14 14 14 15 15 15

d. [1] 11 12 13 14 15 11 12 13 14 15 11 12 13 14 15

23. Which one of the following is the correct outcome of the command rep(55:50,
each=3) ?

a. [1] 55 54 53 52 51 50 55 54 53 52 51 50 55 54 53 52 51 50

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

c. [1] 50 50 50 51 51 51 52 52 52 53 53 53 54 54 54 55 55 55

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

15
24. Which one of the following is the correct outcome of the commands

x <- matrix(nrow=4, ncol=4, data=1:12, byrow=F)

rep(x, each=2) ?

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

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

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

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

25. Which one of the following is the correct outcome of the command
rep(c("CLASS10", " CLASS20", " CLASS30"), each=3) ?

a. [1] "CLASS10" "CLASS10" "CLASS10" " CLASS20" " CLASS20"


" CLASS20" " CLASS30" " CLASS30" " CLASS30"

b. [1] "CLASS10" "CLASS20" "CLASS30" " CLASS10" " CLASS20"


"CLASS30" " CLASS10" " CLASS20" " CLASS30"

c. [1] CLASS 10 20 30 CLASS 10 20 30

d. [1] CLASS 10 10 10 CLASS 20 20 20 CLASS 30 30 30

16
MOOC Course - Introduction to R Software

Answers of Assignment 3
1. b

2. b

3. d

4. c

5. b

6. c

7. a

8. a

9. b

10. d

11. b

12. a

13. c

14. b

15. a

16. d

17. a

18. c

19. d

20. b

21. c

22. a

23. b

24. b

25. a

17
MOOC Course - Introduction to R Software

July 2019

Assignment 4
1. Which one of the following is the correct outcome of the command
sort(c(25,50,38,35,96,71,72,49,65,86), decreasing = FALSE)?

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

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

c. [1] 25 35 38 49 50 65 71 72 86 96

d. [1] 96 86 72 71 65 50 49 38 35 25

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

sort(c(25,50,38,35,96,71,72,49,65,86), decreasing = TRUE)?

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

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

c. [1] 25 35 38 49 50 65 71 72 86 96

d. [1] 96 86 72 71 65 50 49 38 35 25

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

order(c(25,50,38,35,96,71,72,49,65,86), decreasing = FALSE)?

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

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

c. [1] 25 35 38 49 50 65 71 72 86 96

d. [1] 96 86 72 71 65 50 49 38 35 25

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


mode(c(100, 230, "130", 87+970, "740+90", 18.7, 10/5))?
a. character

b. numeric

c. list

d. data frame

2
5. Which one of the following is the correct outcome of the command x[[2]] wher
e x <-list (c("class1", "class2", "class3", "class4"), seq(fr
om=20, to=25), rep(30:37, each=2)) ?
a. [1] "class1" "class2" "class3" "class4"

b. [1] 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37

c. [1] 20 21 22 23 24 25

d. [1] "class2" 52 30

6. Which one of the following is the correct outcome of the command x[[3]][2]
where x <-list (c("class1", "class2", "class3", "class4"), seq
(from=20, to=25), rep(30:37, each=2)) gives an output as
a. [1] "class3"

b. [1] 30

c. [1] 31

d. [1] 30 30

3
7. Which one of the following is the correct outcome of the command x[3][2] where

x <-list (c("class1", "class2", "class3", "class4"), seq(from=


20, to=25), rep(30:37, each=2))?
a. "class3"

b. 22

c. 31

d. "NULL"

8. Which one of the following is the correct outcome of the command x[3] where

x <-list (c("class1", "class2", "class3", "class4"), seq(from=


20, to=25), rep(30:37, each=2)) ?
a. [1] "class1" "class2" "class3" "class4"

b. [1] 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37

c. [1] 20 21 22 23 24 25

d. [1] "class3", 22, 31

4
9. Which one of the following is the correct outcome of the command x[(x<50)]
where
x <- c(70, 35, 127, 535, 238, 437, 189, 562, 16, 27, 17, 361,
78, 152, 149, 121, 47, 2, 1, 252) ?

a. [1] 35 16 27 17 47 2 1

b. [1] 70 127 535 238 437 189 562 361 78 152 149 121 252

c. [1] TRUE

d. [1] FALSE

10. Which one of the following is the correct outcome of the command
x[(x + x^2 < 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] 70 35 127 535 238 437 189 562 16 27 17 361 78 152


149 121 47 252

b. [1] 2 1

c. [1] NULL

d. [1] TRUE

5
11. Which one of the following is the correct outcome of the command
order(x[(x^2 - 18*x > 300)]) 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] 2 14 1 10 13 3 12 11 7 5 15 9 6 4 8

b. [1] TRUE

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

d. [1] NULL

12. If y <- 25:35 then which one of the following is the correct outcome of the c
ommand y[-(3:10)] ?
a. [1] 35 26 25

b. [1] 25 26 35

c. [1] -35 -26 -25

d. [1] -25 -26 -35

6
13. Consider the list z <- list(x1 = "sections", x2 = 30:35). Which
of the following is the correct command to change the element x2 by numbers?

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

14. Consider the list z <- list(x1 = "sections", x2 = 30:35). Which


one of the following is the correct outcome of the command z["x2"] ?

a. [1] "sections"
b. [1] "30:35"

7
c. [1] 35 34 33 32 31 30
d. [1] 30 31 32 33 34 35

15. Which one of the following is the correct outcome of the command
factor(c(15,20,20,20,30,30,45,45,45,50,50,50,50)) ?

a.
[1] 15 20 20 20 30 30 45 45 45 50 50 50 50
Levels: 15 20 30 45 50

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

c.
[1] 15 20 20 20 30 30 45 45 45 50 50 50 50
Levels: 10 10 20 20 30 30

d.
[1] 1 3 2 3 4
Levels: 10 10 20 20 30 30

8
16. Which one of the following is the correct outcome of the following commands?
data = c(15,20,20,20,30,30,45,45,45,50,50,50,50)
factor(data)
levels(data) = c('A','B','C','D','E')
data
a.
[1] 15 20 20 20 30 30 45 45 45 50 50 50 50
attr(,"levels")
[1] "A" "B" "C" "D" "E"
b.

[1] 15 20 30 45 50
attr(,"levels")
[1] "A" "B" "C" "D" "E"

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

d.
[1] B A C D
attr(,"levels")
[1] "15" "20" "30" "45" "50"

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

x = factor(c(15,20,20,20,30,30,45,45,45,50,50,50,50),
levels=c(15,20,30,45,50),ordered=TRUE) ?

a.

[1] 15 < 20 < 30 < 45 < 50


Levels: 15 20 20 20 30 30 45 45 45 50 50 50 50

b.

[1] 15 20 30 45 50
Levels: 15 20 20 20 30 30 45 45 45 50 50 50 50

c.

[1] 15 20 20 20 30 30 45 45 45 50 50 50 50
Levels: 15 < 20 < 30 < 45 < 50

d.
[1] 15 20 20 20 30 30 45 45 45 50 50 50 50
Levels: 15 20 30 45 50

10
18. Which one is the correct outcome of the command
factor( c(rep("apple",2), c(rep("banana",3), rep("orange",
4)))) ?
a.
[1] apple banana orange
Levels: apple apple banana banana banana orange orange orang
e orange

b.
[1] orange orange orange orange banana banana banana ] apple
apple

Levels: orange banana apple

c.
[1] apple banana orange apple banana orange banana orange or
ange
Levels: apple banana orange

d.
[1] apple apple banana banana banana orange orange orange
orange

11
Levels: apple banana orange

19. Which one of the following is the correct outcome of the command
unclass(factor( c(x), levels=c("high school", "graduation", "p
ost graduation") )) where x = c("high school", "graduation", "
post graduation", "graduation", "high school", "post graduatio
n", "high school", "post graduation") ?

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"

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

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

as.factor(c(10, 20, 20, 30, 30, 30, 40, 40, 50, 50, 50) ) ?
a.
[1] 10 20 30 40 50
Levels: 10 20 3 40 50

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

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

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

13
MOOC Course - Introduction to R Software

Answers of Assignment 4
1. c

2. d

3. a

4. a

5. c

6. b

7. d

8. b

9. a

10. b

11. c

14
12. b

13. b

14. d

15. a

16. c

17. d

18. d

19. a

20. c

15
MOOC Course - Introduction to R Software

July 2019

Assignment 5

1. 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] 2/33333

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

print("The average marks in biology is", mean(12,18,25,12,14),


"in final year.", digits=5) ?
a. [1] "The average marks in biology is" mean(12,18,25,12,14) "

in final year."

b. [1] The average marks in biology is 12.000 in final year.

c. [1] "The average marks in biology is"

d. [1] The average marks in biology is mean(12,18,25,12,14) in

final year.

1
3. Which one of the following is the correct outcome of the command
print("The average marks in biology is"); print(mean(12,18,25,
12,14)); print("in final year.")?
a. [1] "The average marks in biology is" 12 "in final year."
b.
[1] "The average marks in biology is"
[1] 12
[1] "in final year."
c. [1] The average marks in biology is mean(12,18,25,12,14)
in final year.
d. [1] The average marks in biology is 12 in final year.

2
4. Let x <- 'My institute is Indian Institute of Technology Kan
pur!\n' then which one of the following are the respective correct outcome of the
commands print(x) and cat(x)?

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

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

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

d.
[1] " My institute is Indian Institute of Technology Kanpur!\n
"
and
My institute is Indian Institute of Technology Kanpur!

3
5. Which one of the following is the correct outcome of the command
print(paste("IIT Kanpur has", 10* 4:6, "students")) ?
a. [1] "IIT Kanpur has" 10* 4 "students" "R course has" 10*
5 "students" "R course has" 10* 6 "students"

b. [1] "IIT Kanpur has 40 students" "IIT Kanpur has 50 studen


ts" "IIT Kanpur has 60 students"

c. [1] "IIT Kanpur has" 10*4 10*5 10*6 "students"

d. [1] IIT Kanpur has 40 students R course has 50 students


R course has 60 students

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


x <- 3375
y <- 121
cat("The cube root of", "x", "is", x^(1/3), "and the square ro
ot of y is", sqrt(y), "!\n") ?
a. The cube root of 3375 is 6 and the square root of 121 is 11 !

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


(1/3) !

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

d. The cube root of x is 15 and the square root of y is 11 !

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

4
x <- 130
cat("The approximate value of cube root of", x, "is", format(x
^(1/3),digits=4),"\n") ?
a. "The approximate value of cube root of 130 is 5.066"
b. "The approximate value of cube root of x is 5.06"
c. The approximate value of cube root of 130 is 5.066

d. The approximate value of cube root of x is 5.067

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


paste("The rents of 3 flats are", c("28 thousands per month",
"29 thousands per month", "30 thousands per month"), collapse
=", and ") ?

a. [1] "The rents of 3 flats are 18 thousands per month, 19 tho


usands per month and 20 thousands per month"

b.
[1] "The rents of 3 flats are 28 thousands per month, and The
rents of 3 flats are 29 thousands per month, and The rents of
3 flats are 30 thousands per month"

c.
[1] "The rents of 3 students are 28 thousands per month, and 2
9 thousands per month, and 30 thousands per month "

d.
[1] "The age of 3 students are 28, 29 and 30 thousands per mon
th"

5
9. Which one of the following is the correct outcome of the command paste("
Students in rows 1, 2 and 3 are", 70:72, sep=":-:") ?
a.
[1] "Students in rows 1 are:-:70" "Students in rows 2 are:-:71
" "Students in rows 3 are:-:72"
b.

[1] "Students in rows 1, 2 and 3 are:-:70:72" "Students in rows 1,


2 and 3 are:-:70:72" "Students in rows 1, 2 and 3 are:-:70:72"
c.

[1] "Students in rows 1, 2 and 3 are:-:70" "Students in rows 1, 2


and 3 are:-:71" "Students in rows 1, 2 and 3 are:-:72"

d.

[1] "Students in rows 1, 2 and 3 are:-:70" "Students in rows 1,


2 and 3 are:-:71" "Students in rows 1, 2 and 3 are:-:72"

10 Which one of the following is the correct outcome of the command paste("
Total number of students in colleges are", 2000:2002, sep="+",
collapse="*") ?
a.
[1] "Total number of students in colleges are+2000*Total numbe
r of students in colleges are+2001*Total number of students in
colleges are+2002"
b.
[1] "Total number of students in colleges are+2000*+2001*+2002
*"
c.
[1] "Total number of students in colleges are *6003"
d.
[1] "Total number of students in colleges are 2000" *+* "Total
number of students in colleges are 2001" *+* "Total number of
students in colleges are 2002"

6
11. Which one of the following is the correct outcome of y where
y=strsplit("Students of Class 1:#: Students of Class 2:#: Stud
ents of Class 3",":#:") ?
a.
[[1]]
[1] "Students of Class 1:#:2:#:3"

b.
[[1]]
[1]
Students of Class 1, Students of Class 2, Students of Class 3,

c.
[[1]]
[1] "Students of Class 1" " Students of Class 2" " Students o
f Class 3"

d.
[[1]]
[1] " Students of Class 1":#:" Students of Class 2":#:" Studen
ts of Class 3"

7
12. Let
y=strsplit("Students of Class 1:#: Students of Class 2:#: Stud
ents of Class 3",":#:")
Which one of the following is the correct command to get the outcome of y as
"Students of Class 2" ?
a. y[1][2]

b. y[2][1]

c. y[[1]][2]

d. [[2]][1]

13. Which one of the following is the correct outcome of the command nchar("S
wayam Benefits Best-in-Class Instructors Empowering you with
knowledge and skills.") ?
a. 88
b. 87
c. 86
d. 84

8
14. Which one of the following is the correct outcome of the command
sub("8", "16", "An Introduction to R Software Course under Swa
yam will be of 8 weeks duration" ) ?
a. [1] "An Introduction to R Software Course under Swayam w
ill be of 8 weeks duration"

b. [1] "An Introduction to R Software Course under Swayam wi


ll be of 16 weeks duration"

c. [1] "An Introduction to R Software Course under Swayam w


ill be of 8-16 weeks duration"

d. [1] "An Introduction to R Software Course under Swayam wi


ll be of 8, 16 weeks duration"

15. Which one of the following is the correct outcome of the command
gsub("Students in College 1", "Students in College 2", "Colleg
e 1 - 2500. College 2 - 3000") ?

a. [1] "College 1 - 2500. College 2 - 3000"

b. [1] "Students in College 1 - 2500." " Students in College 1


- 3000"

c. [1] "Students in College 2 - 2500." " Students in College 2


- 3000"

d. [1] "Students in College 2 - 2500." " College 1- 3000"

9
16. Which one of the following is the correct outcome of the command tolower
("InDIan InStItUtE Of TEchNOloGY KAnpuR") ?
a. [1] "Indian Institute Of Technology Kanpur")

b. [1] "indian institute of technology kanpur"

c. [1] "iNdiAN iNsTiTuTe oF technology kaNPUr")

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

17. Which one of the following is the correct outcome of the command toupper
("Institute Of National Importance in Indian States") ?

a. [1] "institute of national importance in indian states"

b. [1] "iNSTITUTE oF nATIONAL iMPORTANCE IN iNDIAN sTATES"

c. [1] "INSTITUTE OF NATIONAL IMPORTANCE IN INDIAN STATES"

d. [1] "Institute Of National Importance in Indian States"

10
18. Which one of the following is the correct outcome of the command grep("ba
cde", c("bacdec", "bacf", "cbbacdea", "adcdeaba", "bacdecdab"
)) ?
a. [1] "bacdec", "cbbacdea", "bacdecdab"

b. [1] "bacf"

c. [1] 1 3 5

d. [1] 3

19. Which one of the following is the correct outcome of the command grep("[n
-s]", letters) ?
a. [1] n-o-p-q-r-s

b. [1] n o p q r s

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

d. [1] 14 15 16 17 18 19

11
20. Which one of the following are the respective correct outcomes of the following c
ommands: eval(1564-3785-467*32-4356+1887) and
eval("1564-3785-467*32-4356+1887") ?

a. -19634 and "1564-3785-467*32-4356+1887"

b. 1564-3785-467*32-4356+1887 and "-19634"

c. -19634 and 1564-3785-467*32-4356+1887

d. -19634 and "-19634" respectively.

12
MOOC Course - Introduction to R Software

Answers of Assignment 5
1. c

2. c

3. b

4. d

5. b

6. d

7. c

8. b

9. d

10 a

11. c

12. c

13. d

14. b

15. a

16. b

17. c

18. c

19. d

20. a

13
MOOC Course - Introduction to R Software

July 2019

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

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

3. Which one of the following is the correct command to extract the variable
villages from a data frame cities ?
a. suzuki$cities
b. name(cities$villages)
c. name(villages$cities)
d. cities$villages

4. Which one of the following is the correct command to extract the information on
the village whose name is Village23 contained in the variable villages from a
data frame cities?
a. villages$cities$Village23
b. cities["Village23", "villages"]
c. Village23$cities$villages
d. Village23[cities, villages]

1
Answer Question 5-7 on the basis of the following information:
Consider the data frame painters in the library MASS. Use command
library(MASS) to load the library painters and use the command
attach(painters) to attach the database painters.

5. Which one of the following is respectively the correct command to draw


information on those painters who have used the "Colour" coded as 5 and are from
"School" B from the data frame painters and what is the corresponding outcome?

a.
subset(painters, Colour==5 & School==B)
and
Composition Drawing Colour Expression School
Pourbus 4 15 6 6 B
Volterra 12 15 5 8 B

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

c.
subset(painters, Colour=='5' & School=='B')
and
Composition Drawing Colour Expression School
Volterra 12 15 5 8 B

d.
subset(painters, Colour=='5' and School=='B')
and
Composition Drawing Colour Expression
Pourbus 4 15 6 6
Volterra 12 15 5 8

2
6. Which one of the following is respectively the correct command to draw the
information on those painters who have used the "Composition" as 12 and
"Expression" is less than 9 and what is the output from the data frame painters?

a.
subset(painters, Composition =='12' & Expression < '9')
and
Composition Drawing Colour Expression School
Del Sarto 12 16 9 8 A
Volterra 12 15 5 8 B
Palma Giovane 12 9 14 6 D
Titian 12 15 18 6 D

b.
subset(painters, Composition =='12' & Expression < 9)
and
Composition Drawing Colour Expression School
Del Sarto 12 16 9 8 A
Volterra 12 15 5 8 B
Palma Giovane 12 9 14 6 D
Titian 12 15 18 6 D

c.
subset(painters, Composition =='12' & 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

3
d.
subset(painters, Composition =12 & Expression < 9)
and
Da Vinci 15 16 4 14 A
Guilio Romano 15 16 4 14 A
Raphael 17 18 12 18 A
Primaticcio 15 14 7 10 B
Barocci 14 15 6 10 C
Vanius 15 15 12 13 C
Corregio 13 13 15 12 E
Domenichino 15 17 9 17 E
The Carraci 15 17 13 13 E
Holbein 9 10 16 13 F
Otho Venius 13 14 10 10 G
Rembrandt 15 6 17 12 G
Rubens 18 13 17 17 G
Van Dyck 15 10 17 13 G
Le Brun 16 16 8 16 H
Le Suer 15 15 4 15 H
Poussin 15 17 6 15 H

4
7. Which one of the following are respectively the correct commands to draw the
information and output on those painters who have used the "Colour" coded as 5 ,
"School" as B when information on the variables "Drawing" and "Expression" is
removed from the data frame painters and its corresponding outcome?

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

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

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

d.
subset(painters, School=="B" & Colour=="5", select=c(-2,-4))
and
Composition Colour School
Volterra 12 5 B

5
8. A comma separated value data file named as marks.csv having header
can be correctly read in R by which of the following command?
a. readcsv("marks.csv", header= TRUE)
b. read.csv("marks.csv", header=FALSE)
c. csvread(marks.csv, header=FALSE)
d. read.csv("marks.csv", header= TRUE)

9. A spread sheet created in MS-Excel software is named as marks.xlsx not


having header. The sheet number 4 of this file can be correctly read in R by which
of the following command?
a. read.xlsx("marks.xlsx", sheetIndex=4, header= FALSE)
b. read.xlsx(marks.xlsx, sheetindex=4, header= FALSE)
c. read.excel("marks.xlsx", sheetIndex=4, header=TRUE)
d. read.xls(marks.xlsx, sheetindex=4, header= TRUE)

10. A spread sheet created in MS-Excel software is named as marks.xlsx having


header. One of the sheets in this file whose name is Chemistry can be read in R
by which of the following command?
a. read.xlsx("marks.xlsx", sheetName="Chemistry", header=FALSE)
b. read.excel("marks.xlsx", sheetName="Chemistry", header=TRUE)
c. read.xlsx("marks.xlsx", sheetName="Chemistry", header=TRUE)
d. read.xlsx("marks.xlsx", name="Chemistry", header=TRUE)

6
MOOC Course - Introduction to R Software

Answers of Assignment 6

1. a

2. c

3. d

4. b

5. c

6. b

7. d

8. d

9. a

10. c

7
MOOC Course - Introduction to R Software

July 2019

Assignment 7

1. Suppose three dice are rolled 15 times and following is the sum of the numbers on t
he upper faces of the dice,17: 16,13,12,12,17,17,16,11,12,12,15,12,16,17. Which one o
f the following is the correct command to obtain the absolute frequencies of this data in
R?

a. table(c(16,13,12,12,17,17,16,11,12,12,15,12,16,17)

b. table(16,13,12,12,17,17,16,11,12,12,15,12,16,17)

c. table(c(16,13,12,12,17,17,16,11,12,12,15,12,16,17))/length(c(16,
13,12,12,17,17,16,11,12,12,15,12,16,17))

d. table(16,13,12,12,17,17,16,11,12,12,15,12,16,17)/length(16,13,
12,12,17,17,16,11,12,12,15,12,16,17)

2. Suppose three dice are rolled 20 times and following are the sum of numbers on the
upper face: 18,18,17,12,12,3,15,3,14,16,17,16,15,16,16,17,14,13,12, 19. Which one of
the following is the correct outcome of the following command in R?

1
table(c(18,18,17,12,12,3,15,3,14,16,17,16,15,16,16,17,14,13,12,
19))

a.
3 12 13 14 15 16 17 18 19
0.10 0.15 0.05 0.10 0.10 0.20 0.15 0.10 0.05
b.
3 12 13 14 15 16 17 18 19
0.2 0.3 0.1 0.2 0.2 0.4 0.3 0.2 0.1

c.
3 12 13 14 15 16 17 18 19
2 3 1 2 2 4 3 2 1

d.
2 3 1 2 2 4 3 2 1
3 12 13 14 15 16 17 18 19

3. Which one of the following is the correct command to obtain the 12nd , 15th, 17th and
19th percentiles of a data vector x in R?
a. percentile(x, probs=c(12%,15%,17%,19%))

b. percentile(x, probs=(0.12,0.15,0.17,0.19))

c. quantile(x, probs=(12%,15%,17%,19%))

d. quantile(x, probs=c(0.12,0.15,0.17,0.19))

2
4. Which one of the following correctly specify the quantiles of a data vector age obtai
ned as an outcome of the command quantile(age, probs = seq(0, 1, 0.20))
in R? 0% 20% 40% 60% 80% 100%

a. 20th

b. 0th,20th,40th,60th,80th,100th

c. 20th,40th,60th,80th

d. 80th

5. Suppose three dice are rolled 15 times and following is the sum of the numbers on t
he upper faces of the dice,17: 16,13,12,12,17,17,16,11,12,12,15,12,16,17. Which of the
following command in R is used to obtain the bar plot of this data based on relative freq
uencies?
a. barplot(16,13,12,12,17,17,16,11,12,12,15,12,16,17)/length(16,13,1
2,12,17,17,16,11,12,12,15,12,16,17)

b. barplot(table(16,13,12,12,17,17,16,11,12,12,15,12,16,17)/length(1
6,13,12,12,17,17,16,11,12,12,15,12,16,17))

c. barplot(c(16,13,12,12,17,17,16,11,12,12,15,12,16,17))/length(c(16,
13,12,12,17,17,16,11,12,12,15,12,16,17)))

d. barplot(table(c(16,13,12,12,17,17,16,11,12,12,15,12,16,17))/length
(c(16,13,12,12,17,17,16,11,12,12,15,12,16,17)))

6. Suppose three dice are rolled 15 times and following is the sum of the numbers on t
he upper faces of the dice,17: 16,13,12,12,17,17,16,11,12,12,15,12,16,17. Which one o
f the following command is used to obtain the histogram of this data in R based on abs
olute frequencies?

3
a. histo(c(16,13,12,12,17,17,16,11,12,12,15,12,16,17))

b. hist(c(16,13,12,12,17,17,16,11,12,12,15,12,16,17))

c. hist(table(16,13,12,12,17,17,16,11,12,12,15,12,16,17))

d. histogram(c(16,13,12,12,17,17,16,11,12,12,15,12,16,17))

7. Suppose the number of persons visiting a shop for 30 consecutive days is recorded
as follows: 220, 374, 351, 561, 425, 652, 743, 489, 539, 764, 470, 776, 689, 534, 578, 5
48, 554, 654, 785, 652, 587, 804, 427, 792, 864, 845, 572, 545, 490, 572. Which one of

4
the following is the correct command to obtain the histogram of this data in R based o
n relative frequencies?

a. hist(c(220,374,351,561,425,652,743,489,539,764,470,776,689, 5
34,578,548,554,654,785,652,587,804,427,792,864,845,572,545, 490,
572), freq=FALSE)

b. hist(c(220,374,351,561,425,652,743,489,539,764,470,776,689, 5
34,578,548,554,654,785,652,587,804,427,792,864,845,572,545, 490,
572), freq=FALSE)

c. hist((220,374,351,561,425,652,743,489,539,764,470,776,689, 534,
578,548,554,654,785,652,587,804,427,792,864,845,572,545, 490,57
2), freq=TRUE)

d. hist(table((220,374,351,561,425,652,743,489,539,764,470,776,68
9, 534,578,548,554,654,785,652,587,804,427,792,864,845,572,545,
490,572)),freq=TRUE)

8. Suppose the number of children getting vaccinated in 20 localities are recorded and
three such numbers get missed. The collected observations are as follows: 220, 351,56
1,425,743,489,NA,470,776,534,578,548,554,NA,785,652,587,427,864,NA,545. Which

5
one of the following is the correct command to obtain the arithmetic mean of this data i
n R?
a. mean(c(220,351,561,425,743,489,NA,470,776,534,578,548,554,NA,78
5,652,587,427,864,NA,545), na.rm=TRUE)

b. mean(c(220,351,561,425,743,489,NA,470,776,534,578,548,554,NA,7
85,652,587,427,864,NA,545),na.rm=T)

c. mean(220,351,561,425,743,489,NA,470,776,534,578,548,554,NA,785,
652,587,427,864,NA,545, na.rm=TRUE)

d. mean((220,351,561,425,743,489,NA,470,776,534,578,548,554,NA,78
5,652,587,427,864,NA,545),na.rm=T)

9. Suppose the number of employed persons is recorded in 15 offices but three observa
tions get missing as follows: 141, 115, 123, 136, NA, 118, 117, 126, NA, 128, 134, 122,
110, 119, 145. Which one of the following is the correct command to obtain the geomet
ric mean of this data in R?

a. prod(c(141,115,123,136,NA,118,117,126,NA,128,134,122,110,119,
145),na.rm=TRUE)^(1/length(c(141,115,123,136,NA,118,117,126,NA,1
28,134,122,110,119, 145),na.rm=TRUE))

6
b. prod(c(141,115,123,136,NA,118,117,126,NA,128,134,122,110,119,
145),na.rm=TRUE)^(1/length(c(141,115,123,136,NA,118,117,126,NA,1
28,134,122,110,119, 145)),removeNA=TRUE))

c. prod(c(141,115,123,136,NA,118,117,126,NA,128,134,122,110,119,
145))^(1/length(c(141,115,123,136,NA,118,117,126,NA,128,134,122,
110,119, 145),na.rm=TRUE))

d. None of these

10. Suppose the number of employed persons is recorded in 20 offices but four observ
ations get missing as follows: 120, 74, 31, 51, 42, NA, 43, 49, NA, 40, 46, 34, 58, 48, 5
5, 54, NA, NA, 57, 80. Which one of the following is the correct command to obtain the
product of this data in R?

a. prod(c(120,74,31,51,42,NA,43,49,NA,40,46,34,58,48,55,54,NA, N
A,57,80),na.rm=true)

b. prod((120,74,31,51,42,NA,43,49,NA,40,46,34,58,48,55,54,NA, NA,
57,80),na.rm=TRUE)

7
c. prod(c(120,74,31,51,42,NA,43,49,NA,40,46,34,58,48,55,54,NA, N
A,57,80), na.rm=TRUE)

d. product(c(120,74,31,51,42,NA,43,49,NA,40,46,34,58,48,55,54,NA,
NA,57,80),na.rm=T)

11. Suppose the hourly salaries of 10 workers are recorded as follows: 95, 114, 125, 10
5, 131, 122, 141, 111, 110, 121. Which one of the following is the correct command to o
btain the harmonic mean of this data in R?
a. length(c(95,114,125,105,131,122,141,111,110,121))/mean(1/c(95,
114,125,105,131,122,141,111,110,121))

b. length(c(95,114,125,105,131,122,141,111,110,121))/(1/mean(c(95,
114,125,105,131,122,141,111,110,121)))

c. 1/mean(1/(95,114,125,105,131,122,141,111,110,121))

d. 1/mean(1/c(95,114,125,105,131,122,141,111,110,121))

12. Suppose the number of pizzas ordered every hour in 12 branches of a chain of pizz
a shop are recorded and three observations get missing as follows: 425, 375, 421, NA,
368, 469, NA, 457, 461, NA, 452, 481. Which one of the following is the correct comma
nd to obtain the median of this data in R?
a. median(c(425,375,421,NA,368,469,NA,457,461,NA,452,481), na.rm=FA
LSE)

b. median(c(425,375,421,NA,368,469,NA,457,461,NA,452,481), na.rm=
TRUE)

c. median((425,375,421,NA,368,469,NA,457,461,NA,452,481), na.rm=T
RUE)

d. median((425,375,421,NA,368,469,NA,457,461,NA,452,481),na.rm=T)

8
13. Suppose the ages of 10 patients are recorded and two observations are missing as
follows: 38, 68, NA, 45, 59, 45, NA, 27, 33, 55. Which one of the following is the correct
command to obtain the standard deviation of this data in R?
a. sqrt(variance(c(38,68,NA,45,59,45,NA,27,33,55), na.rm=TRUE))

b. sqrt(var(c(38,68,NA,45,59,45,NA,27,33,55),na.rm=FALSE))

c. sqrt(var(c(38,68,NA,45,59,45,NA,27,33,55), na.rm=TRUE))

d. sqrt(var(c(38,68,NA,45,59,45,NA,27,33,55),na.rm=true))

14. Suppose the number of employed persons is recorded in ten offices but two observ
ations get missing as follows: 45, 55, 15, NA, 37, 46, NA, 28, 24, 33. Which one of the f
ollowing is the correct command to obtain the range of this data in R:
a. range(c(45,55,15,NA,37,46,NA,28,24,33), na.rm=TRUE)

b. maximum(c(45,55,15,NA,37,46,NA,28,24,33), na.rm=TRUE)-minimum
(c(45,55,15,NA,37,46,NA,28,24,33), na.rm=TRUE)

c. max(c(45,55,15,NA,37,46,NA,28,24,33), na.rm=TRUE)-min(c(45,55,
15,NA,37,46,NA,28,24,33), na.rm=TRUE)

d. max[c(45,55,15,NA,37,46,NA,28,24,33), na.rm=TRUE]-min[c(45,55,
15,NA,37,46,NA,28,24,33), na.rm=TRUE]

9
15. Suppose the number of songs played on 10 channels of a radio in 3 hours time are
recorded and three observations are missing as follows: 19,25,13,NA,17,NA,11,13,26,N
A,32. Which one of the following is the correct command to obtain the interquartile rang
e of this data in R?
a. IQRange(c(19,25,13,NA,17,NA,11,13,26,NA,32),na.rm=TRUE)

b. QR(c(19,25,13,NA,17,NA,11,13,26,NA,32),na.rm=TRUE)

c. IQR[c(19,25,13,NA,17,NA,11,13,26,NA,32),na.rm=TRUE]

d. IQR(c(19,25,13,NA,17,NA,11,13,26,NA,32),na.rm=TRUE)

16. Suppose the mileages of 10 cars in kilometers are recorded as follows: 34, 32, 31, 2
3, 33, 30, 25, 26, 31. Which one of the following is the correct command to obtain the m
1 n
ean absolute deviation around median ( MD( x)  | xi  x | ) of this data in R where x
n i 1
is the median of given data ?
a. sum(abs((34,32,31,23,33,30,25,26,31)-median((34,32,31, 23,33,3
0,25,26,31))))/length((34,32,31, 3,33,30,25,26,31))

b. sum(abs(c(34,32,31,23,33,30,25,26,31)-median(c(34,32,31,23,33,3
0,25,26,31))))/length(c(34,32,31,23,33,30,25,26,31))

c. sum(absolute(c(34,32,31,23,33,30,25,26,31)-mean(c(34,32,31,23,
33,30,25,26,31))))/length(c(34,32,31,23,33,30,25,26,31))

10
d. mean(abs(c(34,32,31,23,33,30,25,26,31)-mean(c(34,32,31,23,33,3
0,25,26,31))))/length(c(34,32,31,23,33,30,25,26,31))

17. Suppose the number of persons giving auditions on ten TV channels are recorded
as follows and two observations get missing: 23, 21, NA, 25, 31, 13, 22, 14, NA, 31. Wh
ich one of the following is the correct command to obtain the boxplot of this data in R?
a. boxplot[c[23,21,NA,25,31,13,22,14,NA,31], na.rm=TRUE]

b. plot.box(c(23,21,NA,25,31,13,22,14,NA,31],), na.rm=TRUE)

c. boxplot(c(23,21,NA,25,31,13,22,14,NA,31), na.rm=TRUE)

d. boxplot(c(23,21,NA,25,31,13,22,14,NA,31],), na.rm=FALSE)

11
18. Suppose the number of persons giving auditions on ten TV channels are recorded
as follows and two observations get missing: 23, 21, NA, 25, 31, 13, 22, 14, NA, 31. Wh
ich one of the following is the correct command to obtain the coefficient of skewness of t
his data in R?
a. skewness[c[23,21,NA,25,31,13,22,14,NA,31], na.rm=TRUE]

b. skewness(c(23,21,NA,25,31,13,22,14,NA,31), na.rm=TRUE)

c. skewness((23,21,NA,25,31,13,22,14,NA,31), na.rm=TRUE)

d. skew(c(23,21,NA,25,31,13,22,14,NA,31), na.rm=TRUE)

19. Suppose the mileages of 10 cars in kilometers are recorded as follows: 34, 32, 31,
23, 33, 30, 25, 26, 31. Which one of the following is the correct command to obtain the
coefficient of kurtosis in R?

a. kurtosis(c(34,32,31,23,33,30,25,26,31))

b. kurt(c(34,32,31,23,33,30,25,26,31))

c. kurt(34,32,31,23,33,30,25,26,31)

d. kurtosis[c(34,32,31,23,33,30,25,26,31)]

12
20. Suppose the number of songs played on 10 channels of a radio in 3 hours time are
recorded and three observations are missing as follows: 19,25,13,NA,17,NA,11,13,26,N
A,32. Which one of the following correctly specify the command to obtain the coefficient
of kurtosis of this data in R and its obtained value?
a. kurtosis(c(19,25,13,NA,17,NA,11,13,26,NA,32), na.rm=FALSE)

b. kurtosis(c(19,25,13,NA,17,NA,11,13,26,NA,32), na.rm=TRUE)

c. kurtosis(c(19,25,13,NA,17,NA,11,13,26,NA,32), na.rm=TRUE)

d. kurt(c(19,25,13,NA,17,NA,11,13,26,NA,32), na.rm=TRUE)

MOOC Course - Introduction to R Software

Answers of Assignment 7
1 a

2. c

3. d

4. b

5. d

13
6. b

7. a

8. a

9. d

10. c

11. d

12. b

13. c

14. c

15. d

16. b

17. c

18. b

19. a

20. c

14
MOOC Course - Introduction to R Software

July 2019

Assignment 8
1. The paired data on medicine given (x) in grams and reduction in blood pressure (y) in m
mHg of to 20 persons is obtained. Which one of the following is the correct command to obt
ain the scatter plot of the following type in R for the given data?
x = c(11.2,12.4,9.5,13.6,10.1,15.2,8.5,11.1,9.0,16.7,11.7,12.0,12.3,
12.5,8.0,7.5,7.8,8.9,9.9,12.6)
y = c(45,35,30,25,42,31,41,28,40,30,32,40,38,35,29,36,31,25,28,29)

45

a. plot(x,y, "l")
40

b. plot(x,y, "s")
35
y

c. plot(x,y, "h")
30

d. plot(x,y, "b")
25

8 10 12 14 16

2. The paired data on medicine given (x) in grams and reduction in blood pressure (y) in m
mHg of to 20 persons is obtained. Which one of the following is the correct command to obt
ain the scatter plot of the following type in R for the given data?

1
x = c(11.2,12.4,9.5,13.6,10.1,15.2,8.5,11.1,9.0,16.7,11.7,12.0,12.3,
12.5,8.0,7.5,7.8,8.9,9.9,12.6)
y = c(45,35,30,25,42,31,41,28,40,30,32,40,38,35,29,36,31,25,28,29)

a. plot(x,y, "l")

45
b. plot(x,y, "h")

40
c. plot(x,y, "s")

35
y
d. plot(x,y, "b")
30
25

8 10 12 14 16

3. The paired data on medicine given (x) in grams and reduction in blood pressure (y) in m
mHg of to 20 persons is obtained. Which one of the following is the correct command to obt
ain the scatter plot of the following type in R for the given data?
x = c(11.2,12.4,9.5,13.6,10.1,15.2,8.5,11.1,9.0,16.7,11.7,12.0,12.3,
12.5,8.0,7.5,7.8,8.9,9.9,12.6)

2
y = c(45,35,30,25,42,31,41,28,40,30,32,40,38,35,29,36,31,25,28,29)

a. plot(x,y, "h")

45
b. plot(x,y, "l")

40
c. plot(x,y, "s")

35
y
d. plot(x,y, "b")

30
25
8 10 12 14 16

4. Which one of the following is the correct command to obtain the scatter plot of the followi
ng type in R for the given data x = c(133,131,136,139,140,150,120,152), y =
c(209,250,231,236,240,231,240,243) and z = c(15,18,20,23,17,16,19,22)
?

3
210 220 230 240 250

150
140
x

a. plots(cbind(x,y,z))

130
120
250
b. plot(c(x,y,z))

240
y

230
220
210
c. pairs(c(x,y,z))

22
20
z

18
d. pairs(cbind(x,y,z))

16
120 130 140 150 16 18 20 22

5. The covariance between the following data


x = c(11.2,9.5,10.1,8.5,9.0,11.7,12.0,12.5,8.0,7.0), and
y = c(3.5,2.5,3.1,2.8,3.0,4.0,3.5,3.6,2.5,2.9) is correctly obtained by whic
h of the following command in R?

4
a. cov((11.2,9.5,10.1,8.5,9.0,11.7,12.0,12.5,8.0,7.0), (3.5,2.5,3.1,
2.8,3.0,4.0,3.5,3.6,2.5,2.9) )

b. cov(c(11.2,9.5,10.1,8.5,9.0,11.7,12.0,12.5,8.0,7.0), c(3.5,2.5,3.
1,2.8,3.0,4.0,3.5,3.6,2.5,2.9) )

c. covar(c(11.2,9.5,10.1,8.5,9.0,11.7,12.0,12.5,8.0,7.0), c(3.5,2.5,
3.1,2.8,3.0,4.0,3.5,3.6,2.5,2.9) )

d. cvar(c(11.2,9.5,10.1,8.5,9.0,11.7,12.0,12.5,8.0,7.0), c(3.5,2.5,3.
1,2.8,3.0,4.0,3.5,3.6,2.5,2.9) )

6. The correlation between the following data


x = c(11.2,9.5,10.1,8.5,9.0,11.7,12.0,12.5,8.0,7.0), and
y = c(3.5,2.5,3.1,2.8,3.0,4.0,3.5,3.6,2.5,2.9) is correctly obtained by whic
h of the following command in R?
a. corr(c(11.2,9.5,10.1,8.5,9.0,11.7,12.0,12.5,8.0,7.0), c(3.5,2.5,
3.1,2.8,3.0,4.0,3.5,3.6,2.5,2.9) )

b. corr((11.2,9.5,10.1,8.5,9.0,11.7,12.0,12.5,8.0,7.0), (3.5,2.5,3.
1,2.8,3.0,4.0,3.5,3.6,2.5,2.9) )

c. cor(c(11.2,9.5,10.1,8.5,9.0,11.7,12.0,12.5,8.0,7.0), c(3.5,2.5,3.
1,2.8,3.0,4.0,3.5,3.6,2.5,2.9) )

d. cor((11.2,9.5,10.1,8.5,9.0,11.7,12.0,12.5,8.0,7.0), (3.5,2.5,3.1,
2.8,3.0,4.0,3.5,3.6,2.5,2.9) )

7. The following paired data is collected on the voltage (in volts) supplied and rotation per
minute (rpm) of a wheel from 10 different machines. Which one of the following correctly
specify the command to obtain the covariance between the claim and surplus from received
premium and the value?

5
Machine RPM Voltage
Machine 1 425 400
Machine 2 373 300
Machine 3 515 430
Machine 4 487 440
Machine 5 434 420
Machine 6 342 290
Machine 7 359 285
Machine 8 458 410
a. covar(c(425,373,515,487,434,342,359,458),c(400,300,430,440,420,2
90,285,410)) and -3916.161 respectively.

b. cov(c(425,373,515,487,434,342,359,458),c(400,300,430,440,420,290,
285,410)) and 3916.161 respectively.

c.
cov[c(425,373,515,487,434,342,359,458),c(400,300,430,440,420,290,28
5,410)] and -3916.161 respectively.

d. covar[c(425,373,515,487,434,342,359,458),c(400,300,430,440,420,29
0,285,410)] and 3916.161 respectively.

8. The following data are the claims (in millions Rupees) for health insurance from 8
different companies along with their surplus from received insurance premium (in millions
Rupees) . Which one of the following correctly specify the command to obtain the
correlation coefficient between the claim and surplus from received premium and its value?

Company Claims Surplus


Company 1 1425 277

6
Company 2 273 100
Company 3 915 120
Company 4 1687 259
Company 5 234 40
Company 6 142 25
Company 7 259 57
Company 8 258 31

a. cor(c(1425,273,915,1687,234,142,259,258),c(277,100,120,259,40,25,
57,31)) and 0.9572336 respectively.

b.
cor(c(1,425,273,915,1,687,234,142,259,258),c(277,100,120,259,40,25,
57,31)) and 0.9572336 respectively.

c.
corr[c(1,425,273,915,1,687,234,142,259,258),c(277,100,120,259,40,25,
57,31)] and 0.857236 respectively.

d. corr[c(1425,273,915,1687,234,142,259,258),c(277,100,120,259,40,25,
57,31)] and 0.857236 respectively.

9. Which one of the following is the correct function to obtain the square root of the sum of
cubes of two numbers?
a.
cubsqrt <- function(x, y) {
res1 <- x^3 + y^3
res2 <- sqrt(res1)
print{paste("The value of sum of", x, "cube and", y, "cube is",
res1, "and its square root is", res2)}
}

7
b.
cubsqrt <- function(x, y) [
res1 <- x^3 + y^3
res2 <- sqrt(res1)
print(paste("The value of sum of", x, "cube and", y, "cube is",
res1, "and its square root is", res2))
]

c.
cubsqrt <- function(x, y) {
res1 <- x^3 + y^3
res2 <- sqrt(res1)
print(paste("The value of sum of", x, "cube and", y, "cube is",
res1, "and its square root is", res2))
}

d.
cubsqrt <- function(x, y) {
res1 <- x^3 + y^3
res2 <- sqrt(res1)
print{paste{"The value of sum of", x, "cube and", y, "cube is",
res1, "and its square root is", res2}}
}

10. Which one of the following is the correct code of the function to obtain the value of
following function on the basis of given data values of x = (x1, x2,..., xn) and y = (y1, y2,...,
yn):

8
4
n
 xi 
  
i 1  yi 
f ( x, y )  
4 4 1/5
n
 xi   n
 xi  
3
    log     
i 1  yi  y
 i 1  i  

a.
x=c(x1,x2,...,xn)
y=c(y1,y2,...,yn)

g <- function(x,y)
{
n <- length(x)
z <- 0
for (i in 1:n)
(
z[i] <- (x[i]/y[i])^4
)
sum(z)
}

f<-function()
{
fxy <- g(x,y)^2/g(x,y)^(1/3) + (log(g(x,y)))^(1/5)
fxy
}

b.
x=c(x1,x2,...,xn),
y=c(y1,y2,...,yn)

g <- function(x,y)
{
n <- length(x)
z <- 0
for (i in 1:n)
{
z[i] <- (x[i]/y[i])^4
}

9
sum(z)
}

f<-function()
{
fxy <- g(x,y)^2/(g(x,y)^(1/3) + (log(g(x,y)))^(1/5))
fxy
}

c.
x=c(x1,x2,...,xn),
y=c(y1,y2,...,yn)

g <- function(x,y)
{
n <- length(x)
z <- 0
for (i in 1:n)
{
z[i] <- (x[i]/y[i])^4
}
sum(z)
}

f<-function()
{
fxy <- g(x,y)^2/g(x,y)^(1/3) + (log(g(x,y)))^(1/5)
fxy
}

d.
x=c(x1,x2,...,xn),
y=c(y1,y2,...,yn)

g <- function(x,y)
[
n <- length(x)
z <- 0
for (i in 1:n)
{
z[i] <- (x[i]/y[i])^4
}
sum(z)

10
]

f<-function()
[
fxy <- g(x,y)^2/(g(x,y)^(1/3) + (log(g(x,y)))^(1/5))
fxy
]

MOOC Course - Introduction to R Software

Answers of Assignment 8

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

11

You might also like