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4, 1, 3, 4, 4, 2, 5, 3, 5, 5, 3, 3, 3,
2, 5, 1, 5, 2, 5, 2, 4, 4, 3, 1, 3, 1, 1, 4, 2, 3, 3, 3, 5, 2, 1, 3, 1, 5, 1, 1, 3, 4, 5, 4, 5, 4, 3, 4, 5, 4, 5,
3, 4, 4, 2, 3, 1, 4, 5, 2, 2, 4, 2, 3, 4, 5, 2, 5, 5, 3, 4
The R command
a. matrix
b. table
c. array
d. Blank space
a. title
b. 24
c. 16
d. main
a. names.arg
b. names
c. barnames
d. 4
d. c(multicolour=5)
5. Suppose three dice are rolled 20 times and the following is the sum of numbers on the u
pper faces: 12, 11, 17, 15, 12, 13, 5, 3, 14, 16, 7, 8, 15, 6, 6, 7, 14, 13, 12, 12. Which one
of the following commands is used to obtain the histogram of this data in R based on absol
ute frequencies?
a. histo(c(12, 11, 17, 15, 12, 13, 5, 3, 14, 16, 7, 8, 15, 6, 6, 7
, 14, 13, 12, 12))
Solution: The command to plot a histogram of a data vector is hist(x) where x is a vector.
6. Suppose the sales in a shop for 20 days (in thousand Rupees) is recorded as follows:
52, 36, 25, 41, 76, 43, 85, 47, 63, 54, 75, 68, 57, 89, 44, 76, 86, 87, 58, 84. Which one of t
he following is the correct command to obtain the histogram of this data in R based on rela
tive frequencies?
a. hist(c(52,36,25,41,76,43, 85,47,63,54,75,68,57,89,44,76,86,87,58,
84), freq=FALSE)
b. hist(c(52,36,25,41,76,43, 85,47,63,54,75,68,57,89,44,76,86,87,
58,84), freq=TRUE)
c. hist((52,36,25,41,76,43, 85,47,63,54,75,68,57,89,44,76,86,87,58,
84), freq=FALSE)
d. hist(table((52,36,25,41,76,43, 85,47,63,54,75,68,57,89,44,76,86,
87,58,84)),freq=TRUE)
Solution: The command to plot a histogram of a data vector is hist(x) where x is a vector an
d freq = T decides whether the frequencies used will be absolute (freq = F means relative).
7. Suppose the sales in three shops – first shop (denoted as 1), second shop (denoted as
2) and third shop (denoted as 3) are recorded in the following data vector sales = c(1,
1,2,1,2,3,2,2,3,3,3,1,2,3,2,2,3,1,1,3,3,1,2,1,3,3,3,2,2,2,2,1,2,2,
1,1,1,3,2,2,1,2,3,2,2,1,2,3,3,2,1,2,2,3,1,1,2,1,2,3,2,3)
Which of the following is the correct command to obtain the pie diagram having the title as
“Sales in shops”?
Solution: The command to plot a pie diagram of a data vector x is pie(table(x)) where the m
ain title of the plot can be specified by main = “”.
8. Which of the following is the correct matching of the commands in column A and the ou
tputs in Column B about the nature of variables for the plots?
Column A Column B
(1) Pie diagram (i) Quantitative variable
(2) Barplot (ii) Qualitative variable
(3) Histogram
Solution: Histogram is drawn for the quantitative data while Barplot and Pie diagram is use
d to represent qualitative data.
9. The paired data on family income (x) in thousand rupees and expenditure on food (y) i
n thousand rupees of 10 families is obtained. Which one of the following is the correct com
mand to obtain the scatter plot of the following type in R for the given data
x = c(11,11,12,15,10,9,8,9,8,7)
y = c(4,4,5,6,5,3,4,3,5,2) ?
a. plot(x,y, "l")
b. plot(x,y, "s")
c. plot(x,y, "h")
d. plot(x,y, "b")
Solution: Scatter plot of bivariate data can be plotted using the command plot(). Here we
may also specify how to join or represent the values of the points together. For example, “
b” joins the points using straight line, “h” puts a vertical bar for each dependent variable va
lue, etc.
10. The paired data on family income (x) in thousand rupees and expenditure on food (y) i
n thousand rupees of 10 families is obtained. Which one of the following is the correct com
mand to obtain the scatter plot of the following type in R for the given data
x = c(11,11,12,15,10,9,8,9,8,7)
y = c(4,4,5,6,5,3,4,3,5,2) ?
a. plot(x,y, "l")
b. plot(x,y, "h")
c. plot(x,y, "s")
d. plot(x,y, "b")
Solution: Scatter plot of bivariate data can be plotted using the command plot(). Here we
may also specify how to join or represent the values of the points together. For example, “
b” joins the points using straight line, “h” puts a vertical bar for each dependent variable va
lue, etc.
11. The paired data on family income (x) in thousand rupees and expenditure on food (y) i
n thousand rupees of 10 families is obtained. Which one of the following is the correct com
mand to obtain the scatter plot of the following type in R for the given data
x = c(11,11,12,15,10,9,8,9,8,7)
y = c(4,4,5,6,5,3,4,3,5,2) ?
a. plot(x,y, "h")
b. plot(x,y, "l")
c. plot(x,y, "s")
d. plot(x,y, "b")
Solution: Scatter plot of bivariate data can be plotted using the command plot(). Here we
may also specify how to join or represent the values of the points together. For example, “
s” joins the points using straight lines parallel to axes.
12.
Which one of the following is the correct command to obtain the scatter plot of the followin
g type in R for the given data
x = c(112,95,101,85,90,117,120,125,80,70)
y = c(35,25,31,28,30,40,35,36,25,29)
z = c(70,60,70,65,60,80,75,50,52,56) ?
a. plots(cbind(x,y,z))
b. plot(c(x,y,z))
c. pairs(c(x,y,z))
d. pairs(cbind(x,y,z))
Solution: Matrix plot of data on more than 2 variables, we use pairs() command with m
atrix as it’s argument with columns representing data on each variable.
13. Which one of the following is the correct function to obtain the square root of the sum
of cubes of three numbers?
a.
sqrtcube <- function{x, y, z} {
f1 <- x^3 + y^3 + z^3
f2 <- (f1)^1/2
print(paste("The value of sum of cubes of", x, y, " and", z,
"is", f1, "and its square root is", f2))
}
b.
sqrtcube <- function(x, y, z) [
f1 <- (x + y + z)^3
f2 <- (f1)^(1/2)
print(paste("The value of sum of cubes of", x, y, " and", z,
"is", f1, "and its square root is", f2))
]
c.
sqrtcube <- function(x, y, z) {
f1 <- x^3 + y^3 + z^3
f2 <- (f1)^(1/2)
print(paste("The value of sum of cubes of", x, y, " and", z,
"is", f1, "and its square root is", f2))
}
d.
sqrtcube <- function(x, y, z) {
f1 <- x^3 + y^3 + z^3
(f2)^2 <- f1
print(paste("The value of sum of cubes of", x, y, " and", z,
"is", f1, "and its square root is", f2))
}
14.
Which one of the following is the correct code of the function to obtain the value of the
following function on the basis of given data values of
x = (x1, x2,..., xn) and y = (y1, y2,..., yn):
3
𝑥𝑖 7
log(∑𝑛
𝑖=1(√𝑦 ) )
𝑖
𝑓(𝑥, 𝑦)
3 𝑥𝑖 3/7 𝑥𝑖 3/7 1/5
𝑒𝑥𝑝( √∑𝑛
𝑖=1( ) )+|(∑𝑛
𝑖=1( ) ) |
√ 𝑦𝑖 √ 𝑦𝑖
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]/sqrt(y[i])
}
sum(z)
}
f<-function()
{
fxy <- log(g(x,y)^(3/7))/exp(g(x,y)^(3/7)) + abs(g(x,y) ^(3/7))
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]/ sqrt(y[i]))^(3/7)
}
sum(z)
}
f<-function()
{
fxy <- log(g(x,y))/(exp(g(x,y)^(1/3)) + abs(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]^3/sqrt(y[i])^4)
}
sum(z)
}
f<-function()
{
fxy <- log(g(x,y))/exp(g(x,y)) + abs(g(x,y))
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]/sqrt(y[i])
}
sum(z)
}
f<-function()
{
fxy <- (log(g(x,y))^(3/7)/(exp(g(x,y))^(3/7) + (abs(g(x,y)))^(3/7)
fxy
}
Solution: Functions are defined using function(x){ argument } syntax, where one function
may be used in the argument of another function which is the case in this example.
1. b
2. d
3. a
4. c
5. b
6. a
7. d
8. a
9. d
10. b
11. c
12. d
13. c
14. b