Objectives

  • Learn R Markdown basics
  • Install an R package
  • Create basic histograms

Instructions

Your group will submit a single document, but every member of your group needs to create their own markdown document and follow the code in the exercise.

1. Crate an R Markdown file in RStudio

Create a new R Markdown file and name it in_class_introductions.Rmd.

  • Choose the output type to be html document

When you first create a new Rmd document, RStudio will populate it with some content. You should delete the auto-populated text and code chunks, but make sure you do not delete the header part of the document.

  • The header begins with three dashes --- on the first line of the file.
  • There is another line of three dashes at the end of the header.
  • Every R Markdown document has to have the header, so make sure you don’t delete it!

2. Create an Introductions section

Content in R markdown documents is arranged using headings. First-level headings have large text, second-level headings are slightly smaller, etc.

A heading should be brief: think of it as the name of a section of your document.

Headings are denoted using the number sign, #, at the beginning of a line.

First-level headings begin with a single #, second-level begin with a double ##, etc.

Make a section called Introductions using a first level heading. In your introduction section, each member should include a sentence that lists their name and major. For example:

Hello, my name is ____ and my major is ____.

3. Create code chunks to install and load palmerpenguins.

One of the great things about R is that you can extend it by installing packages. Just use the install.packages() function.

For this exercise your group will need to install the palmerpenguins package, which contains data collected from 3 species of penguin.

Make a new first-level heading and call it Installing and Loading Packages.

Create a code chunk and place the following code in it:

install.packages("palmerpenguins")

You only need to install a package once. After the package installs, you should put a comment character at the beginning of the line so that you don’t re-install the package every time!

After you’ve successfully installed a package, you have to tell R to load it into memory using the library() or require() functions.

  • I prefer to use require()

Make another code chunk in which you’ll use the require() function to load the penguins data into R’s memory:

require("palmerpenguins")

4. Inspect the Penguins Data

Now you’ll have the penguins data loaded into R’s memory.

Note: even though penguins object is loaded, it may not be visible in the Environment window.

In general, datasets that are loaded from packages won’t show up in the environment window, even though they are available for use.

Create a new first-level heading called Data Inspection

Create a new code chunk and use the head() function to print the first 6 lines of the penguins data.

  • I’ll let you figure out the code for this.
  • Note the names of the columns.

5. Knit your document to an html file

Finally, you can hit the knit button in RStudio to render your R markdown file into a html document.

One group member should upload the file into Moodle.