--- title: "Module 1, Assignment 2: Getting to Know the Team" author: "Ellen Bledsoe, Lily McMullen" format: html execute: eval: false --- ```{r} #| include: false knitr::opts_chunk$set(echo = TRUE) ``` # 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. ```{r} # 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. ```{r} # Write your code here ``` 2. Subset the `counts` vector using a condition (not index) that returns values from the vector that are greater than 5. ```{r} # Write your code here ``` 3. Calculate the average number of penguins that were counted. (Hint: the `mean()` function will calculate the average.) ```{r} # 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. ```{r} team_data <- read.csv("data/team_antarctica.csv") ``` 4. Take a look at the data and answer the following questions (0.5 points each). a. What are the dimensions of the data (how many rows and how many columns)? b. Name a column that has *categorical* data. c. Name a column that has *numeric* data. d. Name a column that has data that could be treated as either *categorical* or *numeric*. *Answer*: 5. 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!) ```{r} # Write your code here ``` 6. 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!) ```{r} # 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. 7. On average, how did people rate their ability to be in a remote location? ```{r} # Write your code here ``` 8. 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. ```{r} # Write your code here ``` 9. 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). ```{r} # Write your code here ``` 10. Calculate the average cold tolerance of people who want blue parkas. Use these steps to think through how to answer this question. a. First, think about how to create a data frame with only people who want blue parkas b. Next, think about how you select the column with the cold tolerance data c. Finally, think about how to calculate the average ```{r} # 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:* ```{r} # 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.