Challenge - 5 Problems
Excel readxl Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of reading a specific sheet?
Consider an Excel file named
Sheet1 contains a column
Sheet2 contains a column
What will be the output of this code snippet?
data.xlsx with two sheets: Sheet1 and Sheet2. Sheet1 contains a column
Value with values 1, 2, 3. Sheet2 contains a column
Value with values 4, 5, 6.What will be the output of this code snippet?
R Programming
library(readxl) data <- read_excel("data.xlsx", sheet = "Sheet2") print(data$Value)
Attempts:
2 left
💡 Hint
Remember the sheet argument specifies which sheet to read.
✗ Incorrect
The code reads the sheet named 'Sheet2' which contains values 4, 5, 6 in the 'Value' column. So printing data$Value outputs [1] 4 5 6.
❓ Predict Output
intermediate2:00remaining
What happens when reading a non-existent sheet?
Given the same Excel file
data.xlsx with sheets Sheet1 and Sheet2, what will happen if you run this code?R Programming
library(readxl) data <- read_excel("data.xlsx", sheet = "Sheet3")
Attempts:
2 left
💡 Hint
Check what happens if the sheet name does not exist.
✗ Incorrect
The read_excel function throws an error if the specified sheet does not exist in the Excel file.
🔧 Debug
advanced2:00remaining
Why does this code fail to read the Excel file?
You want to read the first 5 rows of an Excel file
data.xlsx using readxl. You write this code:R Programming
library(readxl) data <- read_excel("data.xlsx", n_max = 5) print(nrow(data))
Attempts:
2 left
💡 Hint
Check the readxl documentation for the n_max argument.
✗ Incorrect
The argument n_max is valid in read_excel and limits the number of rows read. So the code prints 5.
🧠 Conceptual
advanced2:00remaining
How to read only specific columns from an Excel sheet?
You want to read only columns named
Age and Name from an Excel sheet using readxl. Which approach is correct?Attempts:
2 left
💡 Hint
The range argument can specify a cell range like "B:C" to read specific columns.
✗ Incorrect
Using the range argument allows reading only specific columns by specifying the cell range. col_types can skip columns but requires knowing positions. Subsetting after reading reads all data. Sheet argument is for sheet names, not columns.
❓ Predict Output
expert3:00remaining
What is the output of this code reading multiple sheets?
Given an Excel file
Jan: 10, 20
Feb: 30, 40
What is the output of this code?
data.xlsx with sheets Jan and Feb, each with a column Sales containing numbers:Jan: 10, 20
Feb: 30, 40
What is the output of this code?
R Programming
library(readxl) library(purrr) sheets <- excel_sheets("data.xlsx") data_list <- map(sheets, ~ read_excel("data.xlsx", sheet = .x)) total_sales <- sum(unlist(map(data_list, "Sales"))) print(total_sales)
Attempts:
2 left
💡 Hint
Sum all sales from both sheets.
✗ Incorrect
Jan sales sum to 30 (10+20), Feb sales sum to 70 (30+40). Total is 100. The code uses purrr::map correctly and sums all sales.