R Programming Questions and Answers – Textual Data Formats – 1

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

Answer: b
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

Answer: d
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

Answer: a
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

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

advertisement
advertisement

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

Answer: b
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

Answer: a
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

Answer: a
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

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

advertisement

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

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

a)

advertisement
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

Answer: c
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
View Answer
Answer: 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.

To practice all areas of R Programming Language, Here is complete set of 1000+ Multiple Choice Questions and Answers.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.