MCQs on Data Input and Output | R

Enhance your skills in Data Input and Output in R with this quiz. Learn how to read/write CSV, Excel, and text files, use packages like readr and data.table, and save R objects efficiently.


MCQs on Data Input and Output in R

Reading and Writing CSV, Excel, and Text Files

  1. Which function is used in R to read a CSV file?
    a) read.csv()
    b) load.csv()
    c) read.table()
    d) import.csv()
  2. What does the write.csv() function do in R?
    a) Writes a CSV file from a data frame to the working directory
    b) Creates a new CSV file
    c) Writes a CSV file from a list to the working directory
    d) Saves data into a CSV format in an external server
  3. Which function would you use in R to read an Excel file?
    a) read_excel()
    b) import_excel()
    c) load_excel()
    d) excel_read()
  4. How do you write data to an Excel file in R?
    a) write_excel()
    b) write.xlsx()
    c) export_excel()
    d) save.xlsx()
  5. In R, which function is used to write a table into a text file?
    a) write.table()
    b) write.text()
    c) text.write()
    d) table.write()
  6. When reading a CSV file with read.csv(), what argument specifies the delimiter?
    a) sep
    b) delim
    c) delimiter
    d) split
  7. What is the default delimiter when reading a CSV file in R using read.csv()?
    a) Tab (\t)
    b) Pipe (|)
    c) Comma (,)
    d) Space ()
  8. Which of the following packages is commonly used to read and write Excel files in R?
    a) dplyr
    b) tidyr
    c) openxlsx
    d) ggplot2
  9. What happens if you pass an incorrect file path to read.csv() in R?
    a) R will create a new file
    b) R will give a warning message and return NULL
    c) R will create a blank CSV file
    d) R will return an error
  10. In R, which function is used to read a file from the internet directly into a data frame?
    a) read_url()
    b) read.csv()
    c) read.table()
    d) read.delim()

Using readr and data.table Packages

  1. Which function in the readr package is used to read a CSV file?
    a) read_csv()
    b) import_csv()
    c) read.csv()
    d) csv_read()
  2. What is the advantage of using readr over base R functions like read.csv()?
    a) readr functions are faster and more memory efficient
    b) readr automatically handles missing values
    c) readr performs data analysis
    d) readr generates plots
  3. What is the default behavior of the readr::read_csv() function in R when reading files?
    a) It reads all columns as character data
    b) It automatically guesses column types
    c) It automatically removes missing values
    d) It creates a new data frame with numeric data
  4. Which of the following functions is used in the data.table package to read large text files?
    a) fread()
    b) read_data()
    c) import_data()
    d) table_read()
  5. What is one of the advantages of using fread() from the data.table package over read.csv()?
    a) It is slower but more flexible
    b) It automatically handles large datasets efficiently
    c) It only works with CSV files
    d) It automatically performs exploratory data analysis
  6. What is the default delimiter for fread() in data.table?
    a) Comma (,)
    b) Semicolon (;)
    c) Tab (\t)
    d) Pipe (|)
  7. Which function in readr is used to read a tab-delimited file?
    a) read_delim()
    b) read_table()
    c) read_tab()
    d) read_text()
  8. How can you control the number of rows read when using fread() in the data.table package?
    a) By setting the nrows argument
    b) By setting the max_rows argument
    c) By specifying num_rows in the function
    d) By specifying row_limit in the function
  9. How do you prevent readr::read_csv() from converting strings to factors in R?
    a) Set the stringsAsFactors = FALSE argument
    b) Use the as.character() function after reading the data
    c) Set convert = FALSE
    d) Use the stringsAsFactors = TRUE argument
  10. Which of the following is a key feature of the data.table package in R?
    a) Fast reading and manipulation of large datasets
    b) Extensive plotting functions
    c) Seamless integration with databases
    d) Built-in machine learning functions

Saving R Objects

  1. What function in R is used to save an object to a file?
    a) save()
    b) write()
    c) store()
    d) save_file()
  2. How do you save multiple R objects to a single file in R?
    a) By using save() with a list of objects
    b) By using write()
    c) By calling save() for each object
    d) By manually appending objects to a file
  3. What file extension is typically used for R data files created with the save() function?
    a) .rdata
    b) .csv
    c) .txt
    d) .rds
  4. Which function is used to load an R object from a saved file?
    a) load()
    b) import()
    c) read()
    d) unload()
  5. How can you save a single R object as an .rds file?
    a) saveRDS()
    b) save()
    c) writeRDS()
    d) write()
  6. What is the primary difference between save() and saveRDS() in R?
    a) save() saves multiple objects, while saveRDS() saves a single object
    b) save() saves objects as .csv files, saveRDS() saves them as .rds files
    c) save() is used for text files, while saveRDS() is used for binary files
    d) There is no difference
  7. Which function would you use to save a data frame as a CSV file?
    a) write.csv()
    b) save.csv()
    c) export.csv()
    d) writeRDS()
  8. What does the readRDS() function do in R?
    a) It reads an R object saved in .rds format
    b) It reads data from a CSV file
    c) It reads data from an Excel file
    d) It reads R objects from a database
  9. In R, what is the purpose of the file.choose() function?
    a) It allows the user to select a file interactively
    b) It checks if a file exists
    c) It automatically sets the working directory
    d) It opens a file in the R console
  10. How can you read a saved .rds file into R?
    a) By using readRDS()
    b) By using load()
    c) By using importRDS()
    d) By using read()

Answers Table

QnoAnswer
1a) read.csv()
2a) Writes a CSV file from a data frame to the working directory
3a) read_excel()
4b) write.xlsx()
5a) write.table()
6a) sep
7c) Comma (,)
8c) openxlsx
9b) R will give a warning message and return NULL
10b) read.csv()
11a) read_csv()
12a) readr functions are faster and more memory efficient
13b) It automatically guesses column types
14a) fread()
15b) It automatically handles large datasets efficiently
16c) Tab (\t)
17a) read_delim()
18a) By setting the nrows argument
19a) Set the stringsAsFactors = FALSE argument
20a) Fast reading and manipulation of large datasets
21a) save()
22a) By using save() with a list of objects
23a) .rdata
24a) load()
25a) saveRDS()
26a) save() saves multiple objects, while saveRDS() saves a single object
27a) write.csv()
28a) It reads an R object saved in .rds format
29a) It allows the user to select a file interactively
30a) By using readRDS()

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top