Look up a museum room
Before you start this intermediate track
Numeric vectors and basic averages. Read data-frame columns and logical filters.
Guided code reading and debugging. Runnable coding challenges are available in JavaScript, Python, and SQL.
Understand it, then try it.
A named vector pairs each value with a useful label. Here the labels are museum rooms and the values are visitor counts. Double brackets retrieve one value using a name stored in another variable. The lookup follows the room name, so rearranging the vector does not change its meaning.
visitors <- c(Orchid = 14, Fossil = 27, Orbit = 8)wanted <- "Fossil"count <- visitors[[wanted]]cat(paste0(wanted, ": ", count), "\n")Each mission is a separate base R script. Run it with Rscript; no packages or input files are needed. Quiz answers show the text printed by cat, without a console prompt.
Track the values line by line. Predict the result before running this example in your own editor.