This set of R Programming Language Multiple Choice Questions & Answers (MCQs) focuses on “Textual Data Formats – 1”.
1. Which of the following is used for reading in saved workspaces?
a) unserialize
b) load
c) get
d) set
View Answer
Explanation: 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
View Answer
Explanation: 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
View Answer
Explanation: 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
View Answer
Explanation: 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
View Answer
Explanation: 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”)
View Answer
Explanation: 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
View Answer
Explanation: 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)
View Answer
Explanation: 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
View Answer
Explanation: 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)
a b 1 1 a
b)
a b 1 2 b
c)
a b 2 1 a
d)
b a
1 a a
Explanation: Multiple objects can be deparsed at once using the dump function and read back in using source.
Sanfoundry Global Education & Learning Series – R Programming Language.
Here’s the list of Best Books in R Programming Language.
- Practice Programming MCQs
- Check R Programming Books
- Apply for Programming Internship
- Check Information Technology Books