---
title: "My Document"
execute:
echo: true
---
Homework 3
Instructions
For this assignment, include all code and relevant output in your rendered html document1.
1 You can set the echo: true
(and other) code chunk option(s) globally (will set it as the document default) by specifying it in your YAML header like so:
Exercises
- Organize your files for this class in a way that facilitates reproducible research.
- You can do this any number of ways, such as:
- Creating a project for this class. If you already have a folder for this class you can retroactively turn it into a project by selecting File > New Project… > Existing Directory and browsing to that folder2.
- Creating a folder for this class and make weekly sub-folders which are each, themselves, projects.3 You would need to retroactively make week 1 and 2 folders projects by using this method. For any new weekly folders you can directly create that directory by selecting File > New Project… > New Directory
- Create your .qmd for this homework within your new project4.
- When you’re done organizing the folder for this class, write out its current organizational structure (i.e. something similar to the solution to lab question 55 with the specific names for files and folders that you used). Write a one-sentence description of how you’ve organized your project/projects for this class.
- You can do this any number of ways, such as:
2 Note: this approach will complicate your file path specification since markdown documents internally set the working directory to the folder they are in when they knit. That will be at odds with the working directory of your project, (one folder-level up from each of your homework assignment .qmds). If you’d like to use this method for organizing your folders/files, you should familiarize yourself with the here
package to limit file path frustration and enable you to set up more complex projects in the future.
3 I highly recommend this approach if the concept of relative versus absolute paths is new(er) to you. If each homework is its own project, your working directory will be set directly to that homework folder which will make relative file paths work whether you’re running code interactively or knitting your .qmd since they will be the same.
4 You’ll notice that the upper-right hand corner of your RStudio IDE now displays the name of that new project. This is your current working directory. Whatever files you create will have a working directory of the folder of the project they’re saved within (except for .qmd files when they are knit in any subfolder of your root project folder.
5 You can embed output-looking text like this example by using a code chunk without the {r}
like so:
```
CSSS 508
Homework1/
...etc...
```
<- rnorm(20, 10, 5) x
- Create the vector above:
- Look at the help file for
rnorm
and in your own words describe what arguments it takes and what it produces. - Which arguments are required and which are optional (if any)?
- What does the
r
inrnorm
stand for? - Using
[
, select every value except the last one - Using
[
, select only values that are greater than 10.
- Look at the help file for
ggplot(mpg, aes(x = class)) +
geom_bar()
ggplot(mpg, aes(x = cty, y = hwy)) +
geom_point()
ggsave("mpg-plot.png")
- Run the code above.
- Which of the two plots is saved as mpg-plot.png? Why?6
- In the files tab of the lower-right pane of your RStudio, look at the project folder for this homework7 and re-write the current organizational structure for this class with any changes that have occurred (i.e. update your answer to question 1.iii.).
6 Hint: Check out the help page!
7 This will depend on which organizational method you chose for question 1.i.
- Go to RStudio Shortcuts and Tips and find one tip that makes sense to you and looks interesting. Describe it and link to its section url8 in your qmd. Maybe practice using it!9
8 See how to link to websites in markdown syntax here
9 No need to demonstrate this in your qmd.
<- tibble(a = seq(1, 10, 2),
y b = c("apple", "banana", "strawberry", "peach", "mango"),
c = c(rep(TRUE, 3), rep(FALSE, 2)))
- Create the tibble above.
10 Run ?seq
to see the help file
11 Run ?rep
to see the help file
> # A tibble: 2 × 1
> b
> <chr>
> 1 banana
> 2 mango
iv) Index y
using $
to arrive at the results:
> [1] TRUE TRUE TRUE FALSE FALSE
v) What does y[3:5, ]
produce? What does :
do?
Due Dates
# | Homework Due | Peer Review Due |
---|---|---|
1 | 7 October | 12 October |
2 | 14 October | 19 October |
3 | 21 October | 26 October |
4 | 28 October | 2 November |
5 | 11 November | 16 November |
6 | 18 November | 21 November |
7 | 25 November | 30 November |
8 | 2 December | 7 December |
9 | 9 December | 14 December |