0
0
R Programmingprogramming~5 mins

read.table and delimiters in R Programming - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the read.table() function in R?

read.table() is used to read data from a file into R as a data frame. It reads tabular data where columns are separated by delimiters.

Click to reveal answer
beginner
Which argument in read.table() specifies the character used to separate columns?

The sep argument defines the delimiter character that separates columns in the input file.

Click to reveal answer
beginner
What is the default delimiter used by read.table() if sep is not specified?

The default delimiter is any whitespace (spaces, tabs). So read.table() treats one or more spaces or tabs as column separators.

Click to reveal answer
intermediate
How do you read a CSV file using read.table()?

Use read.table(file, sep=",", header=TRUE) to read a CSV file where columns are separated by commas and the first row contains column names.

Click to reveal answer
beginner
What does the header argument do in read.table()?

The header argument tells R whether the first line of the file contains column names (header=TRUE) or not (header=FALSE).

Click to reveal answer
What is the default delimiter used by read.table() in R?
AWhitespace (spaces or tabs)
BComma
CSemicolon
DColon
Which argument do you use to specify the delimiter in read.table()?
Adelimiter
Bsep
Cdelim
Dsplit
How do you tell read.table() that the first row contains column names?
Afirstrow=TRUE
Bnames=TRUE
Cheader=TRUE
Dcolnames=TRUE
Which of these is the correct way to read a comma-separated file with headers using read.table()?
Aread.table(file, sep=" ", header=TRUE)
Bread.table(file, sep=";", header=FALSE)
Cread.table(file, sep="\t", header=FALSE)
Dread.table(file, sep=",", header=TRUE)
If your data columns are separated by tabs, what should you set sep to in read.table()?
A"\t"
B","
C";"
D" "
Explain how to use read.table() to read a file where columns are separated by semicolons and the first row contains headers.
Think about how to tell R about the delimiter and headers.
You got /3 concepts.
    Describe what happens if you use read.table() without specifying the sep argument on a file where columns are separated by commas.
    Consider what the default separator is and how it affects reading comma-separated data.
    You got /3 concepts.