Question: ** R CODE ** I often want to repeat some section of code some number of times. For example, I might want to create a

** R CODE **

I often want to repeat some section of code some number of times. For example, I might want to create a bunch plots that compare the density of a t-distribution with specified degrees of freedom to a standard normal distribution. ```{r, fig.height=3, message=FALSE, warning=FALSE} library(ggplot2) df <- 4 N <- 1000 x.grid <- seq(-4, 4, length=N) data <- data.frame( x = c(x.grid, x.grid), y = c(dnorm(x.grid), dt(x.grid, df)), type = c( rep('Normal',N), rep('T',N) ) ) # make a nice graph myplot <- ggplot(data, aes(x=x, y=y, color=type, linetype=type)) + geom_line() + labs(title = paste('Std Normal vs t with', df, 'degrees of freedom')) # actually print the nice graph we made print(myplot) ``` a) Use a `for` loop to create similar graphs for degrees of freedom $2,3,4,\dots,29,30$. b) In retrospect, perhaps we didn't need to produce all of those. Rewrite your loop so that we only produce graphs for $\left\{ 2,3,4,5,10,15,20,25,30 ight\}$ degrees of freedom. *Hint: you can just modify the vector in the `for` statement to include* *the desired degrees of freedom.*

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!