library(learnr) library(nycflights13) options(tutorial.event_recorder = learnr:::debug_event_recorder) tutorial_options( exercise.eval = FALSE, exercise.checker = function(label, user_code, envir_result, ...) { if (is.null(envir_result)) list(message = "Bad code!", correct = FALSE) else list(message = "Nice job!", correct = TRUE, location = "append") } )
This is the intro to the whole ball of wax.
# filter the flights table to include only United and American flights
flights
filter(flights, ...)
filter(flights, UniqueCarrier=="AA")
filter(flights, UniqueCarrier=="AA" | UniqueCarrier=="UA")
In betwixt and in between.
library(dplyr) nycflights <- nycflights13::flights
# Change the filter to select February rather than January nycflights <- filter(nycflights, month == 1)
Modify this code so that it prints only the first 5 rows of the mtcars
dataset:
head(mtcars, n = 5)
mtcars <- head(mtcars, n = 5) print(mtcars) mtcars <- head(mtcars, n = 5) print(mtcars) mtcars <- head(mtcars, n = 5) print(mtcars)
#
#
Modify this plot to use the cyl
variable rather than the wt
variable:
library(ggplot2) qplot(mpg, cyl, data = mtcars)
mtcars <- head(mtcars, n = 5) mtcars
Add a range selector to the following dygraph:
library(dygraphs) dygraph(ldeaths)
question("What number is the letter A in the English alphabet?", allow_retry = TRUE, answer("8"), answer("14"), answer("1", correct = TRUE), answer("23") )
quiz( question("What number is the letter A in the *English* alphabet?", answer("8"), answer("14", message = "That's $x+ 1$ **insane!**"), answer("1", correct = TRUE, message = "Good job!"), answer("23") ), question("Where are you right now? (select ALL that apply)", answer("Planet Earth", correct = TRUE), answer("Pluto", message = "How could you think we are on Pluto?"), answer("At a computing device", correct = TRUE), answer("In the Milky Way", correct = TRUE), incorrect = "Incorrect. You're on Earth, in the Milky Way, at a computer." ), question(sprintf("Suppose $x = %s$. Choose the correct statement:", 42), answer(sprintf("$\\sqrt{x} = %d$", 42 + 1)), answer(sprintf("$x ^ 2 = %d$", 42^2), correct = TRUE), answer("$\\sin x = 1$") ) )
# a false 'unexpected comma' diagnostic was printed at the end of line 4 below GapMinderPlot( LifeExpectency, countries = c("Germany", "United States", "New Zealand", "China", "India", "Japan")) GapMinderPlot(LifeExpectency)
for (i in seq(1,5)){ x <- i }
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.