250+ TOP MCQs on Textual Data Formats and Answers

R Programming Language Multiple Choice Questions on “Textual Data Formats”.

1. Which of the following is used for reading in saved workspaces?
a) unserialize
b) load
c) get
d) set

Answer: b
Clarification: unserialize is used for reading single R objects in binary form. Load is used for reading in saved workspaces. Search by name for an object (get) or zero or more objects (mget).

2. Point out the wrong statement?
a) write.table is used for for writing tabular data to text files (i.e. CSV) or connections
b) writeLines is used for for writing character data line-by-line to a file or connection
c) dump is used for for dumping a textual representation of multiple R objects
d) all of the mentioned

Answer: d
Clarification: There are analogous functions for writing data to files.

3. ________ is used for outputting a textual representation of an R object.
a) dput
b) dump
c) dget
d) dset

Answer: a
Clarification: dump is used for dumping a textual representation of multiple R objects.

4. Which of the following argument denotes if the file has a header line?
a) header
b) sep
c) file
d) footer

Answer: a
Clarification: sep is a string indicating how the columns are separated.

5. Point out the correct statement?
a) unserialize is used for converting an R object into a binary format for outputting to a connection
b) save is used for saving an arbitrary number of R objects in binary format to a file
c) The read.data() function is one of the most commonly used functions for reading data
d) save is not used for saving an arbitrary

Answer: b
Clarification: read.table reads a file in table format and creates a data frame from it.

6. Which of the following statement would read file “foo.txt”?
a) data <- read.table(“foo.txt”)
b) read.data <- read.table(“foo.txt”)
c) data <- read.data(“foo.txt”)
d) data <- data(“foo.txt”)

Answer: a
Clarification: R will automatically skip lines that begin with a #.

7. Which of the following function is identical to read .table?
a) read.csv
b) read.data
c) read.tab
d) read.del

Answer: a
Clarification: The read.csv() function is identical to read.table except that some of the defaults are set differently (like the sep argument).

8. Which of the following code would read 100 rows?
a) initial <- read.table(“datatable.txt”, nrows = 100)
b) tabAll <- read.table(“datatable.txt”, colClasses = classes)
c) initial <- read.table(“datatable.txt”, nrows = 99)
d) initial <- read.table(“datatable.txt”, nrows = 101)

Answer: a
Clarification: You can use the Unix tool wc to calculate the number of lines in a file.

9. What will be the output of the following R code?

> y <- data.frame(a = 1, b = "a")
> dput(y)

a)

structure(list(a = 1, b = list(1L, .Label = "a", class = "factor")), .Names
= c("a",
"b"), row.names = c(NA, -1L), class = "data.frame")

b)

list(list(a = 1, b = list(1L, .Label = "a", class = "factor")), .Names
= c("a",
"b"), row.names = c(NA, -1L), class = "data.frame")

c)

structure(list(a = 1, b = structure(1L, .Label = "a", class = "factor")), .Names
= c("a",
"b"), row.names = c(NA, -1L), class = "data.frame")

d) Error

Answer: c
Clarification: dput() output is in the form of R code and that it preserves metadata like the class of the object, the row names, and the column names.

10. Which of the following is used for reading tabular data?

> y <- data.frame(a = 1, b = "a")
> dput(y, file = "y.R")
> new.y <- dget("y.R")
> new.y

a)

b)

c)

d)

View Answer

Answer: a
Clarification: Multiple objects can be deparsed at once using the dump function and read back in using source.

Leave a Reply

Your email address will not be published. Required fields are marked *