# vector with counts of penguins
counts <- c(2, 9, 4, 3, 6, 7, 1, 0, 3)Module 1, Assignment 2: Getting to Know the Team
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.
- Write a line of code that returns the 2nd value in the
countsvector.
# Write your code here- Subset the
countsvector using a condition (not index) that returns values from the vector that are greater than 5.
# Write your code here- Calculate the average number of penguins that were counted. (Hint: the
mean()function will calculate the average.)
# Write your code hereData 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")- Take a look at the data and answer the following questions (0.5 points each).
- What are the dimensions of the data (how many rows and how many columns)?
- Name a column that has categorical data.
- Name a column that has numeric data.
- Name a column that has data that could be treated as either categorical or numeric.
Answer:
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- 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 hereWhen 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.
- On average, how did people rate their ability to be in a remote location?
# Write your code here- What are the minimum and maximum distances that would be traveled by a team member to get to Antarctica? Use the
min()andmax()functions.
# Write your code here- 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 hereCalculate the average cold tolerance of people who want blue parkas. Use these steps to think through how to answer this question.
First, think about how to create a data frame with only people who want blue parkas
Next, think about how you select the column with the cold tolerance data
Finally, think about how to calculate the average
# Write your code hereBonus (up to 2 points)!
What animal should be on our team flag?
- First, create a vector called
mascotthat has only the values from theteam_flagcolumn. - Next, use the
table()function on themascot. - 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 hereTurning in Your Assignment
- Make sure your name is filled in at the top of the document.
- 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.
- To download the HTML file from Posit Cloud, click the empty box to the left of it in the Files panel.
- Click the blue gear at the top of the Files panel and choose Export.
- Put your last name at the front of the file name when prompted, then click Download. The file is now in your Downloads folder.