Homework 3

Instructions

For this assignment, include all code and relevant output in your rendered html document1.

Exercises

  1. Organize your files for this class in a way that facilitates reproducible research. To be clear, there is no code to write up in this section, just text. Follow the style guidelines from lecture for filenames/folder names.
    1. You can do this any number of ways, such as:
      1. 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 folder.
      2. Creating a folder for this class and making weekly subfolders which are each, themselves, projects. You would need to retroactively make Week 1 and 2 folders projects by using the method above. For any new weekly folders you can directly create that directory by selecting File > New Project… > New Directory.
    2. Create your .qmd for this homework in an appropriate place within your new project2.
    3. 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 53 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.

x <- rnorm(20, 10, 5)
  1. Create the vector above:
    1. Look at the help file for rnorm and in your own words describe what arguments it takes and what it produces.
    2. Which arguments are required and which are optional (if any)?
    3. What does the r in rnorm stand for?
    4. Using [, select every value of x except the last one. You can show just the code you used or both the code and what it prints out.
    5. Using [, select only values of x that are greater than 10. You can show just the code you used or both the code and what it prints out.

ggplot(mpg, aes(x = class)) +
  geom_bar()
ggplot(mpg, aes(x = cty, y = hwy)) +
  geom_point()
ggsave("mpg-plot.png")
  1. Run the code above. You don’t have to include the plots or the code in your submission; you can run it in your RStudio console to see the results, then write up your answers to the following questions in the assignment you submit.
    1. Which of the two plots is saved as mpg-plot.png? Why?
    2. In the files tab of the lower-right pane of your RStudio, look at the project folder for this homework 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.).

y <- tibble(a = seq(1, 10, 2), 
            b = c("apple", "banana", "strawberry", "peach", "mango"), 
            c = c(rep(TRUE, 3), rep(FALSE, 2)))
  1. Create the tibble above.
    1. What does seq do in this example and what arguments does it take?
    2. What does rep do in this example and what arguments does it take?
    3. Index y using [ to arrive at the results:
> # 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?

Footnotes

  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:

    ---
    title: "My Document"
    execute:
      echo: true
    ---
    ↩︎
  2. 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/subfolder of the project they’re saved within.↩︎

  3. You can embed output-looking text like this example by using a code chunk without the {r} (just three backticks above and below) like so:

    ```
    CSSS 508
      Homework1/
      ...etc...
    ```
    ↩︎