library(learnr) library(gradethis) knitr::opts_chunk$set(echo = FALSE) gradethis_setup( pass.praise = TRUE, fail.hint = FALSE, fail.encourage = TRUE, maybe_code_feedback = FALSE)
quiz( question( "Which of the following commands is equivalend to `xx <- 2`?", answer('assign("xx", 2)', correct = TRUE), answer("xx -> 2"), answer("name('xx', 2)"), answer("assign(xx, 2)"), allow_retry = TRUE, random_answer_order = TRUE ), question( "Which of the following statements about objects and names is correct?", answer("Every object can only have a unique name, just as every name must point to a unique object)!"), answer("While every object must have a unique name, each name can point to none, one, or several objects!"), answer("Names can point to multiple objects, and objects can have more than one name."), answer("An object can have many names, only every name must point to a unique object", correct = TRUE), allow_retry = TRUE, random_answer_order = TRUE ), question( "What can you do to remove all object-name assignment in your current R session?", answer("Restart the R session!", correct = TRUE), answer("Call `rm(name)` for each assignment.", correct = TRUE), answer("Click on the broom in the upper right environment panel in R-Studio", correct = TRUE), answer("Call `rm(list=ls())` in the console.", correct = TRUE), answer("Remove the assignment from the script and re-run the script from above."), allow_retry = TRUE, random_answer_order = TRUE ) )
Compute the following mathematical operations in R:
$$10+25$$
grade_result( pass_if(~identical(.result, 10+25)) )
$$50\cdot 2$$
grade_result( pass_if(~identical(.result, 50*2)) )
$$\frac{27}{4}$$
grade_result( pass_if(~identical(.result, 27/4)) )
$$500-650$$
grade_result( pass_if(~identical(.result, 500-650)) )
$$2^4$$
grade_result( pass_if(~identical(.result, 2**4)) )
$$\sqrt{3}\cdot 60$$
grade_result( pass_if(~identical(.result, sqrt(3)*60)) )
$$50 \cdot (4+2)^3$$
grade_result( pass_if(~identical(.result, 50*(4+2)**3)) )
Do the following chain computation in R. Assign a name to each intermediate result and then return the overall result.
Hint: avoid overwriting existing R functions such as c()
since this can be
confusing. Better use, e.g., names such as var_c
instead.
\begin{align} a &= 10 + 25\ b &= a \cdot 40\ c &= b - 100\ d &= c \cdot 3\ e &= \sqrt{d}\ f &= \frac{e}{1000}\ g &= f^3 \end{align}
a_ <- 10 + 25 b_ <- a_ * 40 c_ <- b_ - 100 d_ <- c_ * 3 e_ <- sqrt(d_) f_ <- e_ / 1000 g_ <- f_^3 g_
grade_result( pass_if(~identical(.result, 0.0002435549)) )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.