0
0
R Programmingprogramming~10 mins

read.table and delimiters in R Programming - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to read a file named 'data.txt' using read.table with default delimiter.

R Programming
data <- read.table('data.txt', sep=[1])
Drag options to blanks, or click blank then click option'
A" "
B"\t"
C","
D";"
Attempts:
3 left
💡 Hint
Common Mistakes
Using comma or tab as separator when the file uses spaces.
Leaving sep empty which causes errors if file is not space-separated.
2fill in blank
medium

Complete the code to read a CSV file named 'data.csv' using read.table with the correct delimiter.

R Programming
data <- read.table('data.csv', sep=[1], header=TRUE)
Drag options to blanks, or click blank then click option'
A"\t"
B","
C" "
D";"
Attempts:
3 left
💡 Hint
Common Mistakes
Using space or tab as separator for CSV files.
Not setting header=TRUE when the file has column names.
3fill in blank
hard

Fix the error in the code to read a semicolon-delimited file named 'data.txt'.

R Programming
data <- read.table('data.txt', sep=[1], header=TRUE)
Drag options to blanks, or click blank then click option'
A","
B"\t"
C" "
D";"
Attempts:
3 left
💡 Hint
Common Mistakes
Using comma or tab as separator for semicolon-delimited files.
Not specifying sep parameter when delimiter is not space.
4fill in blank
hard

Fill both blanks to read a tab-delimited file 'data.tsv' with headers.

R Programming
data <- read.table('data.tsv', sep=[1], header=[2])
Drag options to blanks, or click blank then click option'
A"\t"
BTRUE
CFALSE
D","
Attempts:
3 left
💡 Hint
Common Mistakes
Using comma as separator for tab-delimited files.
Setting header=FALSE when the file has headers.
5fill in blank
hard

Fill all three blanks to read a file 'data.txt' with pipe '|' delimiter and no headers.

R Programming
data <- read.table('data.txt', sep=[1], header=[2], stringsAsFactors=[3])
Drag options to blanks, or click blank then click option'
A"|"
BFALSE
CTRUE
Attempts:
3 left
💡 Hint
Common Mistakes
Using comma or tab as separator for pipe-delimited files.
Setting header=TRUE when no headers exist.
Not setting stringsAsFactors=FALSE causing unwanted factor columns.