You are on page 1of 5

MOOC Course - Introduction to R Software

July 2017

Solution to Assignment 1

1. To get a help on any function, the command is to write ? followed by the name of
the function.

Hence option c is correct.

2. To seek help from R software, one needs to type help.start() in R console.

Hence option d is correct.

3. For having a demonstration of a package in R software, function demo() is used


where the name of the package is written inside the arguments.

Hence option c is correct.

4. To have an example in R software, the function example() is used where the


name of the function is written inside the arguments.

Hence option a is correct.

5. When the given commands

x=23
y=x^2
z=y^3+x^2

1
are typed and executed over the R console, one get the output 148036418 for the var
iable z. First a value 23 is assigned to x by x=23 , then it is squared by y using y=x^
2 and finally y^3+x^2 is computed.
Hence option c is correct.

6. The output for 2+3-4*6/3-2^3/4+7-6*2**3/2+2-4+5 in R console after


calculations is -19. Such an output is obtained using the usual order of
mathematical operations.

Hence option b is correct.

7. Output for -478/365-12^3/47-6**2**3-27^-(1/3)-7^6*3 in R console


after calculations is -2032601. Such an output is obtained using the usual order
of mathematical operations.

Hence option a is correct.

8. When command c(1,2,3,4)*c(1,2,2,4)^c(2,1,3,2)**c(1,2,3,3)-


c(2,3,402653185,262145) is executed over the R console, it gives the output -
1 1 -1 -1. Such an output is obtained by using element wise operations.

Hence option b is correct.

9. The R console returns 1722 538 2746 726 after doing calculation for
c(2,3,4,5)^c(2,3)+ c(12,23,14,25)^c(3,2)- c(5,6,7,8)*c(2,3) =
c(2^2, 3^3, ^2, 5^3)+ c(12^3, 23^2, 14^3, 25^2) - c(5^2, 6^3,
7^2, 8^3). Such an output is obtained by using element wise operations.

Hence option a is correct.

2
10. One needs to be careful in using the feature in R about the mathematical
operations with two vectors and their dimensions. The option b does not possess
this property of operation for vectors. Hence output of option b gives a output with a
warning that longer object length is not a multiple of shorter
object length.

Hence option b is correct.

11. The output of abs(c(5,6,7,8)*c(-1,-2,-3,-4)- c(5,6,7,8)*c(-2,3)


- c(1,2,4,4)^-c(1,2,-1,-2)) is based on the element wise operations and
on the use of multiplication, inverse and absolute function. It gives an outcome 4.00
30.25 11.00 72.00 .

Hence option a is correct.

12. The output of c(1,2,4,4)^-c(1,2,-1,-2)* c(1,2,4,4)^-c(1,2,-1,-


2) is 1.0000 0.0625 16.0000 256.0000. This is based on the use of
multiplication, inverse and absolute function.

Hence option b is correct.

13. The operation x %% y denotes the operation modulus (x mod. y). For
example 5%%2 is 1 and the operation x %/% y denotes the integer division, e.g.
5%/%2 is 2. On this basis, using the concept of element wise operations in R
console, the operation c(15,16,17,18)%/%8* c(52,64,71,86)%/%c(4,3)+
c(53,66,87,78)%%7 returns 17 45 37 57 as output .

Hence option c is correct.

3
14. The commands for getting maximum, minimum and product of the elements of a
vector are max(), min() and prod() with the values being given inside the
brackets. On this basis, R console provides 3570.46 as an output of
max(c(62,83,44,75)^-c(9,-3))/min(c(52,62,71,85)^c(2,3))-
prod(c(1,2,1,2)^c(1,2)) + max(c(12,13,14,15)^c(2,3)).

Hence option c is correct.

15. If x is vector, then function ceiling(x) returns the smallest integers greater
than or equal to the corresponding elements of x. Similarly sum and prod functions
provide the summation and product of the values in x vector. The statement of
commands 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)) returns
the values -503 -694 -527 -990.

Hence option b is correct.

16. For a vector x, the functions floor(x) and round(x) return the largest integer
less than or equal to the corresponding elements of x and just the integer part of
corresponding elements of x respectively. Therefore the statement
ceiling(c(5,6,7,8)^c(2,3))+floor(c(5,6,7,8)^c(2,3))+
floor(c(2,3,4,5)^-c(1,-2))- round(c(5,6,7,8)^c(2,3)) returns the
output 25 225 49 537.

Hence option b is correct.

17. The outcome of round(c(21,23,44,15)^c(-11,-12)+


sqrt(c(35,16,37,88)^c(12,3))*sqrt(c(21,13,14,45)^-c(1,-2)))is
based on the use of function round and sqrt which provide the values rounded off
to the next integer and the square root of the values in the vector in x. The outcomes
comes out to be as 401142446 832 685719226 37148.

Hence option a is correct.

4
18. The outcome of the command round(sum(c(12,13,871,789))-
prod(c(21,22,13,14,51))) in R console is based on the use of the functions
round and prod which provide the values rounded off to the next integer and the
product of the values in the vector in x. The outcome of this statement comes out to
be as -4286599.

Hence option c is correct.

19. The command X1 <- c(123,258,318,624) assigns the values


123,258,318,624 to X1. Then X2 <- sqrt(X1^3)+X1/X1^2-X1**(1/2)
assigns sqrt(X1^3)+X1/X1^2-X1**(1/2) X2 which is based on the use of
function sqrt to find the square root of the values 123,258,318,624 based on
element wise operation. For the given vector X1, the output of the command
sqrt(X1^3)+X1/X1^2-X1**(1/2) is 1353.054 4128.035 5652.923
15562.537 when executed over the R console.

Hence option a is correct.

20. The outcome of c(11,12,34,24)^-c(2,2,-1,-2)* c(1,2,3,4)-


c(12,14,11,16)%/%c(4,3)+min(c(120,14,14,15)^c(1,3))+
max(c(56,12,71,15)^c(2,3)) is based upon the use of the functions to find the
inverse, maximum and minimum of the values with element wise operation. The
outcome turns out to be 5052.008 5051.014 5155.000 7354.000.

Hence option c is correct.

You might also like