# A variable is a letter, word, or series of words that can store a value (number, word, vector, data set) in R
<-20 myVariable
Homework Module 1.2 Key
Your Name (replace me)
Date (replace me)
In the questions below, use R code to answer questions. For any non-coding questions, give your answer as a comment.
- In the code chunk below, define what a variable is (using comments), and create a variable
myVariable
set equal to 20.
- Describe what a vector is in R, and create a sample vector below:
# A vector is a type of variable that stores multiple values
<-c(1,2,3,4,5) myVector
- In the code chunk below, load the tidyverse. Why might we do this, and what is the tidyverse for?
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ ggplot2 3.5.1 ✔ tibble 3.2.1
✔ lubridate 1.9.3 ✔ tidyr 1.3.1
✔ purrr 1.0.2
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
# Loading the tidyverse provides additional functions for R programming.
# The tidyverse is a series of packages and functions written by data scientists to make working with data easier.
- Describe what a function is. What is an argument? How might you learn about what functions exist in R?
# A function is a built in command that performs common tasks.
# An argument is a thing (variable, data set, etc.) that you provide to a function as input.
# You can learn about what functions exist by searching the internet.
- What is camel case? Describe some best practices for naming variables.
# Camel case is a syntax for creating variable names in which the first word is lower case, and subsequent words are title case, with no spaces.
# Variables should be named in such a manner that they are readable (e.g. with camel case), and that they accurately describe what the variable contains.
- What is the mean for the survey responses for self reported willingness to settle in a remote environment (hint: use the
remote
column)
<-read_csv("teamAntarcticaData.csv") teamAntarcticaData
Rows: 75 Columns: 12
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (7): Timestamp, school, swim, animals, parkaColor, teamFlag, distance
dbl (5): fishing, cold, remote, bedsideManner, cooking
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
<-teamAntarcticaData$remote
remote
mean(remote)
[1] 3.28
- What does the glimpse function do (we have not covered it)? How might you learn more about it?
# glimpse() lets you view your dataset in a transposed view (columns become rows)
# You can learn more about glimpse() by running help(glimpse). You can also find documentation/look for examples by searching the internet.