library(RTutor) # Adapt the working directory below and then run setup chunk in RStudio. setwd("D:/libraries/RTutor/examples") ps.name = "myps"; sol.file = paste0(ps.name,"_sol.Rmd") libs = c("ggplot2") # character vector of all packages you load in the problem set #name.rmd.chunks(sol.file) create.ps(sol.file=sol.file, ps.name=ps.name, libs=libs,addons = "quiz") # The following line directly shows the problem set # in the browser show.ps(ps.name,launch.browser=TRUE, auto.save.code=FALSE,sample.solution=FALSE)
a) We often want to compute some summary statistic of a vector. For example:
#< task_notest x = 10:20 # Computing the sum of x sum(x) #>
Now compute the mean of x.
mean(x) #< hint display("Use Google, e.g. search for 'R compute mean'.") #>
Well, in some occasions one can just guess the name of an R function. The function to compute the mean of a vector, or matrix is called 'mean'. Usually, it is much quicker to goggle than to guess function names, however.
a) Let y be a vector that contains the squared elements of x. Then show y.
#< task x = 1:5 #> y = x^2 y
We can also plot in a problem set
library(ggplot2) qplot(x,y)
Here are examples for generating random numbers
runif(3,0,100) sample(1:100,5)
Here is a quiz that will be nicely shown in the shiny version.
question: What is the 'oddest' prime? sc: - 2* - 3 - 5 - 7 success: Well, of course the answer is debatable... failure: Try again.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.