0
0
R Programmingprogramming~10 mins

read.csv and write.csv 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 CSV file named 'data.csv' into a variable called df.

R Programming
df <- [1]("data.csv")
Drag options to blanks, or click blank then click option'
Awrite.table
Bwrite.csv
Cread.table
Dread.csv
Attempts:
3 left
💡 Hint
Common Mistakes
Using write.csv instead of read.csv
Using read.table without specifying separator
2fill in blank
medium

Complete the code to save the data frame df to a CSV file named 'output.csv'.

R Programming
[1](df, "output.csv")
Drag options to blanks, or click blank then click option'
Aread.csv
Bsave.csv
Cwrite.csv
Dexport.csv
Attempts:
3 left
💡 Hint
Common Mistakes
Using read.csv instead of write.csv
Using save.csv which does not exist
3fill in blank
hard

Fix the error in the code to read a CSV file with headers.

R Programming
df <- read.csv("data.csv", [1] = TRUE)
Drag options to blanks, or click blank then click option'
Aheader_row
Bheader
Chead
Dheaders
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'headers' instead of 'header'
Using 'head' which is a different function
4fill in blank
hard

Fill both blanks to read a CSV file with semicolon separator and save it back with row names excluded.

R Programming
df <- read.csv("data.csv", sep = [1])
write.csv(df, "output.csv", row.names = [2])
Drag options to blanks, or click blank then click option'
A";"
BTRUE
CFALSE
D","
Attempts:
3 left
💡 Hint
Common Mistakes
Using comma as separator when file uses semicolon
Setting row.names to TRUE which includes row names
5fill in blank
hard

Fill all three blanks to read a CSV file without converting strings to factors, then write it with UTF-8 encoding and no row names.

R Programming
df <- read.csv("data.csv", stringsAsFactors = [1])
write.csv(df, "output.csv", fileEncoding = [2], row.names = [3])
Drag options to blanks, or click blank then click option'
ATRUE
BFALSE
C"UTF-8"
D"ASCII"
Attempts:
3 left
💡 Hint
Common Mistakes
Leaving stringsAsFactors as TRUE causing factors
Using wrong encoding like ASCII
Including row names unintentionally