Data In The Wild
  1. Module 1
  2. Assignment 2
  • Home
  • Contact Us
  • For Instructors

  • Module 1
    • Overview
    • 1.1: Introduction to R and RStudio
    • 1.2: Intro to Coding in R
    • 1.3: Introduction to the tidyverse
    • Assignment 2
    • Assignment 3
  • Module 2
    • Overview
    • 2.1: Good Food Gone Bad
    • 2.2: Plotting with ggplot2
    • 2.3: Data Visualization
    • 2.4: Exploring geom Functions
    • 2.5: Module 2 Wrap-Up
    • Assignment 1
    • Assignment 2
    • Assignment 3
  • Module 3
    • Overview
    • 3.1: Leopard Seals
    • 3.2: T-Tests
    • 3.3: Comparing (Multiple) Means
    • Assignment 1
    • Assignment 2
  • Module 4
    • Overview
    • 4.1: Combining Datasets (Joins & Binds)
    • 4.2: K-Nearest Neighbor
    • 4.3: Roads and Regressions
    • 4.4: Multiple Regression
    • 4.5: Writing Functions
    • Assignment 1
    • Assignment 2
    • Assignment 3
    • Assignment 4
  • Module 5
    • Overview
    • 5.1: Population Growth
    • 5.2: Sustainable Fishing
    • 5.3: Comparing Populations
    • Assignment 1
    • Assignment 2
    • Assignment 3
  • Final Project

  • Resources

On this page

  • Assignment Description
    • Purpose
    • Task
    • Criteria for Success
  • Assignment Questions
    • Vectors
    • Data Frames
    • Bonus (up to 2 points)!
  • Turning in Your Assignment
  1. Module 1
  2. Assignment 2

Module 1, Assignment 2: Getting to Know the Team

Author

Ellen Bledsoe, Lily McMullen

Assignment Description

Purpose

The goal of this assignment is to get comfortable using R to look at 1- and 2-dimensional data sets using base R.

Task

Write R code to successfully answer each question below.

Criteria for Success

  • Code is within the provided code chunks
  • Code chunks run without errors
  • Code produces the correct result
    • Code that produces the correct answer will receive full credit
    • Code attempts with logical direction will receive partial credit
  • Written answers address the questions in sufficient detail

Assignment Questions

Each question is worth 2 points unless otherwise specified.

Vectors

Let’s start working with vectors, or 1-dimensional data, first.

Run this chunk of code to create a vector of data to use. It represents the number of penguins counted at different sites.

# vector with counts of penguins
counts <- c(2, 9, 4, 3, 6, 7, 1, 0, 3)
  1. Write a line of code that returns the 2nd value in the counts vector.
# Write your code here
  1. Subset the counts vector using a condition (not index) that returns values from the vector that are greater than 5.
# Write your code here
  1. Calculate the average number of penguins that were counted. (Hint: the mean() function will calculate the average.)
# Write your code here

Data Frames

Now that we’ve practiced with vectors, let’s move on to 2-dimensional data.

Remember those questions about our trip to Antarctica from the survey you completed the first week of classes? It’s time to play around with that data!

The following code chunk will read the data into RStudio. Be sure to run it before trying to answer the questions!

Once you run the code, you will see a data frame called team_data show up in the environment.

team_data <- read.csv("data/team_antarctica.csv")
  1. Take a look at the data and answer the following questions (0.5 points each).
    1. What are the dimensions of the data (how many rows and how many columns)?
    2. Name a column that has categorical data.
    3. Name a column that has numeric data.
    4. Name a column that has data that could be treated as either categorical or numeric.

Answer:

  1. Take a look at the data frame using the head() function. Typically, head() provides the first 6 rows of data.

    Modify one of the arguments in head() so that the line of code prints the first 10 rows. (If you aren’t sure how to do that, remember how you can look for help about functions!)

# Write your code here
  1. Using what you know about subsetting data frames, write a line of code that returns the parka color for the team member in row 4. (Hint: count the columns!)
# Write your code here

When we have a large data set like this, it is often helpful to summarize the data in some way. The next few questions will help us get a better understanding of the content of the data set.

  1. On average, how did people rate their ability to be in a remote location?
# Write your code here
  1. What are the minimum and maximum distances that would be traveled by a team member to get to Antarctica? Use the min() and max() functions.
# Write your code here
  1. Subset using a condition to return the rows of data only for people who rated their fishing skills as a 5. Retain all of the columns in those rows. (Hint: numbers do not need quotation marks around them).
# Write your code here
  1. Calculate the average cold tolerance of people who want blue parkas. Use these steps to think through how to answer this question.

    1. First, think about how to create a data frame with only people who want blue parkas

    2. Next, think about how you select the column with the cold tolerance data

    3. Finally, think about how to calculate the average

# Write your code here

Bonus (up to 2 points)!

What animal should be on our team flag?

  • First, create a vector called mascot that has only the values from the team_flag column.
  • Next, use the table() function on the mascot.
  • For full points, make sure you type out which animal that should be our mascot below; providing only the code will result in partial credit.

Answer:

# Write your code here

Turning in Your Assignment

  1. Make sure your name is filled in at the top of the document.
  2. Click the Render button at the top of this document. This will produce an HTML file that opens in a new tab and also saves to the Files panel on the bottom-right of your screen.
  3. To download the HTML file from Posit Cloud, click the empty box to the left of it in the Files panel.
  4. Click the blue gear at the top of the Files panel and choose Export.
  5. Put your last name at the front of the file name when prompted, then click Download. The file is now in your Downloads folder.

2026, University of Arizona & Lewis & Clark College

 
  • Made with Quarto