Assignment11 L45-L49
Assignment11 L45-L49
July 2023
Assignment 11
1. A comma separated value data file named as school.csv having header can b
e correctly read in R by which of the following command?
a. readcsv("school.csv", header= TRUE)
b. read.csv("school.csv", header=FALSE)
c. csvread(school.csv, header=FALSE)
d. read.csv("school.csv", header= TRUE)
Solution: The command to read the .csv file is read.csv(), where header =T specifies th
at the data has a header.
2. A tabular data file named as school1.txt where the values are separated by bla
nk space and having header can be correctly read in R by which of the following com
mand?
a. read.table("school1.txt", header= TRUE, sep = " ")
b. read.txt("school1.txt", header=FALSE, sep = " ")
c. tabularread(school1.txt, header=FALSE, sep = " ")
d. read.table(school1.txt, header= TRUE, sep = )
Solution: The command to read the .txt file for data is read.table(), where header =T sp
ecifies that the data has a header, and separator is specified by sep = “ ”.
3. A spreadsheet created in MS-Excel software is named as tax.xlsx . The sheet nu
mber 4 of this file can be correctly read in R by which of the following commands in libr
ary readxl?
a. read_excel("tax.xlsx", sheet=4)
b. read.excel("tax.xlsx", sheetIndex=4)
c. Read_excel("tax.xlsx", sheet=4)
d. read.excel(tax.xlsx, sheetIndex=4)
Solution: The command to read the .xlsx file for data is read_excel(), where sheet inde
x is specified by sheet = .
Solution: The command to read the .xlsx file for data is read_excel(), where sheet nam
e is specified by sheet = “”.
5. Suppose two dice are rolled 10 times and following is the difference of the numbers
on the upper faces of the dice: 4,5,2,3,4,2,2,3,3,1. Which one of the following is the cor
rect command to obtain the absolute frequencies of this data in R?
a. table(c(4,5,2,3,4,2,2,3,3,1))
b. table(4,5,2,3,4,2,2,3,3,1)
c. table(c(4,5,2,3,4,2,2,3,3,1))/length(c(4,5,2,3,4,2,2,3,3,1))
d. table(4,5,2,3,4,2,2,3,3,1)/length(4,5,2,3,4,2,2,3,3,1)
Solution: The command to get the frequency table of data vector x is table(x).
6. Suppose three dice are rolled 20 times and the following is the sum of numbers on t
he upper faces: 18, 18, 17, 12, 12, 13, 15, 13, 14, 16, 17, 16, 15, 16, 16, 17, 14, 13, 1
2, 12, 12. Which one of the following is the correct outcome of the following command i
n R?
table(c(18, 18, 17, 12, 12, 13, 15, 13, 14, 16, 17, 16, 15, 16, 1
6, 17, 14, 13, 12, 12, 12))
a.
12 13 14 15 16 17 18
0.25 0.15 0.10 0.10 0.20 0.15 0.10
b.
5 3 2 2 4 3 2
12 13 14 15 16 17 18
c.
12 13 14 15 16 17 18
5 3 2 2 4 3 2
d.
0.25 0.15 0.10 0.10 0.20 0.15 0.10
12 13 14 15 16 17 18
Solution: The command to get the frequency table of data vector x is table(x).
7. Which one of the following is the correct command to obtain the 5th, 7th, and 9th decil
es of a data vector x in R?
a. decile(x, probs=c(5%,7%,9%))
b. decile(x, probs=(0.5,0.7,0.9))
c. quantile(x, probs=(5%,7%,9%))
d. quantile(x, probs=c(0.5,0.7,0.9))
Solution: The command to get the quantiles of a data vector x is quantile(x, probs = ),
where “probs = “ specifies the probabilities for quantiles (can be a number or a vector w
ith elements in [0,1]). For deciles, we specify the decilenumber/10 as probability.
8. Which one of the following correctly specifies the quantiles of marks stored in the da
ta 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
Solution: The command to get the quantiles of a data vector x is quantile(x, probs = ),
where “probs = “ specifies the probabilities for quantiles (can be a number or a vector w
ith elements in [0,1]).
9. Suppose two dice are rolled 10 times and the following difference of the numbers o
n the upper faces of the dice: 4,5,2,3,4,2,2,3,3,1. Which of the following command in R
is used to obtain the bar plot of this data based on relative frequencies?
a. barplot(4,5,2,3,4,2,2,3,3,1)/length(4,5,2,3,4,2,2,3,3,1)
b. barplot(table(4,5,2,3,4,2,2,3,3,1)/length(4,5,2,3,4,2,2,3,3,1))
c. barplot(c(4,5,2,3,4,2,2,3,3,1))/length(c(4,5,2,3,4,2,2,3,3,1)))
d. barplot(table(c(4,5,2,3,4,2,2,3,3,1))/length(c(4,5,2,3,4,2,2,3,3,
1)))
Solution: The Bar plot of a data vector x is given by barplot() command, but the argum
ent has to be in table format.
10. Suppose two dice are rolled 10 times and the following difference of the numbers o
n the upper faces of the dice: 4,5,2,3,4,2,2,3,3,1. Which of the following command in R
is used to obtain the bar plot of this data based on absolute frequencies having the ma
in title as “Sum of Numbers on Dice” and all the bars are filled in red colour?
Solution: The Bar plot of a data vector x is given by barplot() command, but the argum
ent has to be in table format. The title is specified by main = “” and color by col = “”.
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