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")
  }
)

intro

This is the intro to the whole ball of wax.

flights

# filter the flights table to include only United and American flights
flights
filter(flights, ...)
filter(flights, UniqueCarrier=="AA")
filter(flights, UniqueCarrier=="AA" | UniqueCarrier=="UA")

YouTube Video

Vimeo Video

in between

In betwixt and in between.

solution {style="margin-top: 50px;"}

library(dplyr)
nycflights <- nycflights13::flights
# Change the filter to select February rather than January
nycflights <- filter(nycflights, month == 1)
This is the hint for the exercise which I just provided.

Viewing Data

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

dygraphs

Add a range selector to the following dygraph:

library(dygraphs)
dygraph(ldeaths) 

quiz

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$")
  )
)

diagnostics buglet

# 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 in

for (i in seq(1,5)){
     x <- i
 }


rstudio/learnr documentation built on Sept. 6, 2024, 11:06 p.m.