Objectives and Concepts

  • Practice creating and manipulating two fundamental R data structure types:
    • vector
    • data.frame

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

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

2. Create a Vectors section

Create a first-level section called Vectors.

3. Vector: Names

In your Vectors (first-level) section, create a second-level heading called Names Create a new code chunk and create a vector of your group members’ names using the c() function
Your vector should be called group_names. For example, I might create a vector using the following code:

group_names = c(
  "Mike Nelson",
  "Meg McLean",
  "Chris Sutherland"
)

4. Vectors: Majors and Graduation Dates

Next, you’ll create two new more second-level headers, each with its own code chunk.

Majors

Call the first second-level header Majors, and within its code chunk make a vector, group_majors, containing each group member’s major.

Note: your majors should appear in the same order that you used in the group_names vector above.

Graduation Year

Your next second-level section should be called Graduation Year and in it you should make a numeric vector, grad_year that contains each student’s expected graduation year.

5. Data Frame

Finally, create a new first-level header and call it Student Info Dataframe.

In a code chunk, use the data.frame() function, along with the vectors you created above, to create a data.frame object called group_info.

group_info should have three columns:

  1. Students’ names
  2. Students’ majors
  3. Students graduation year

6: Data Frame Questions

Create a final first-level heading and answer the following questions:

  1. Can elements in a vector be of different types?
  2. How is a data.frame different from a matrix?

Final Doc Report

Render your Rmd source into an html document and one student per group will upload to Moodle. The document needs the following sections (which are described above):

  • Vectors (first level heading)
    • Names (second level)
    • Majors (second level)
    • Graduation Year (second level)
  • Student Info Dataframe (first level heading)
  • Questions (first level heading)