0
0
R Programmingprogramming~5 mins

read.csv and write.csv in R Programming - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the read.csv() function do in R?

read.csv() reads data from a CSV file and loads it into R as a data frame, which is like a table you can work with.

Click to reveal answer
beginner
How do you save a data frame to a CSV file in R?

You use the write.csv() function, which writes the data frame to a CSV file on your computer.

Click to reveal answer
intermediate
What argument do you use in read.csv() to prevent R from converting strings to factors?

Use stringsAsFactors = FALSE to keep text as plain strings instead of factors.

Click to reveal answer
intermediate
What does the row.names = FALSE argument do in write.csv()?

It tells R not to write row numbers as a separate column in the CSV file.

Click to reveal answer
intermediate
If you want to read a CSV file with a different separator, should you use read.csv() or another function?

You should use read.table() with the sep argument, because read.csv() assumes commas as separators.

Click to reveal answer
What is the default separator used by read.csv()?
ASemicolon (;)
BTab (\t)
CComma (,)
DSpace
Which argument in write.csv() prevents writing row names to the file?
Arow.names = TRUE
Brow.names = FALSE
Cheader = FALSE
DstringsAsFactors = FALSE
How do you read a CSV file without converting text columns to factors?
AUse <code>stringsAsFactors = FALSE</code>
BUse <code>stringsAsFactors = TRUE</code>
CUse <code>header = FALSE</code>
DUse <code>sep = ";"</code>
Which function would you use to read a CSV file with semicolon separators?
Aread.table(sep = ";")
Bwrite.csv()
Cread.csv()
DreadLines()
What type of object does read.csv() return?
AMatrix
BVector
CList
DData frame
Explain how to read a CSV file into R and save it back after making changes.
Think about loading data, modifying it, then writing it back.
You got /4 concepts.
    Describe the purpose of the stringsAsFactors argument in read.csv().
    Consider how R treats text data by default.
    You got /3 concepts.