Professional Documents
Culture Documents
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.
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.
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.
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.
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 .
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)).
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.
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.
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.