The purpose of this second assignment is to introduce you to working in RMarkdown. This will be the primary file format in which you will save and present your work for this class.
As noted previously, for this and all future assignments, you MUST type all commands in by hand. Do not copy & paste except for troubleshooting purposes (i.e., if you cannot figure out what you mistyped).
Early on, you may have a lot of trouble getting your code to run due to minor typos. This is normal.
Remember, you are learning to read and write a new (coding) language. As with learning any new languages, we learn from practice - and from correcting our mistakes.
(Note: Remember that, when following instructions, always substitute “LastName” for your own last name and substitute YEAR_MO_DY for the actual date. E.g., Day_CRM495_RAssign2_2022_01_21)
In the first assignment, you learned about writing and running R code
in an R Script file. You also saw how running certain commands (e.g.,
ggplot) from an R Script file will generate results in the
RStudio Console. For Assignment 2, you will learn to create a new R
Markdown file, and you will complete the remainder of your assignment in
Like an R Script file, an R Markdown file can be used to write and run R code. However, an R Markdown file also can do much more than that. For instance, you can write and edit text, write and run R code, and generate statistical results and plots directly in the RMarkdown file. You can even create entire books and webpages using R Markdown. In fact, both this assignment and the first one were created using R Markdown.
R Markdown is an essential tool for producing reproducible research because, with it, we can thoroughly document and simultaneously provide detailed explanations for all of our coding decisions in a project - from opening and manipulating data, to recoding and combining variables, to summarizing and analyzing data, to creating and modifying figures.
We will start by simply opening and saving a new R Markdown file. For more detailed instructions, check out Danielle Navarro’s video series on using R Markdown.
The dialogue box asks for a Title, an Author, and a Default Output Format for your new R Markdown file.
OK to create your new R Markdown file. It
should look like this:
The new R Markdown file contains a simple pre-populated template
to show users how to do basic tasks like add settings, create text
headings and text, insert R code chunks, and create plots. I recommend
you read through the template the first time you open a new RMarkdown
file as it contains useful information. However, it can also be a little
overwhelming for new users. So we are going to delete everything after
the metadata and second set of three dashes (i.e., after the YAML