Skip to content

Commit

Permalink
Render site
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Oct 10, 2024
1 parent 1442a28 commit 72f52a8
Show file tree
Hide file tree
Showing 5 changed files with 570 additions and 3,680 deletions.
8 changes: 4 additions & 4 deletions help.html
Original file line number Diff line number Diff line change
Expand Up @@ -353,14 +353,14 @@ <h2><strong>Why are my changes not taking effect? It’s making my results look
<p>Here we are creating a new object from an existing one:</p>
<pre class="r"><code>new_rivers &lt;- sample(rivers, 5)
new_rivers</code></pre>
<pre><code>## [1] 230 202 610 1270 460</code></pre>
<pre><code>## [1] 320 1770 680 259 780</code></pre>
<p>Using just this will only print the result and not actually change <code>new_rivers</code>:</p>
<pre class="r"><code>new_rivers + 1</code></pre>
<pre><code>## [1] 231 203 611 1271 461</code></pre>
<pre><code>## [1] 321 1771 681 260 781</code></pre>
<p>If we want to modify <code>new_rivers</code> and save that modified version, then we need to reassign <code>new_rivers</code> like so:</p>
<pre class="r"><code>new_rivers &lt;- new_rivers + 1
new_rivers</code></pre>
<pre><code>## [1] 231 203 611 1271 461</code></pre>
<pre><code>## [1] 321 1771 681 260 781</code></pre>
<p>If we forget to reassign this can cause subsequent steps to not work as expected because we will not be working with the data that has been modified.</p>
<hr />
</div>
Expand Down Expand Up @@ -409,7 +409,7 @@ <h2><strong>Error: object ‘X’ not found</strong></h2>
<p>Make sure you run something like this, with the <code>&lt;-</code> operator:</p>
<pre class="r"><code>rivers2 &lt;- new_rivers + 1
rivers2</code></pre>
<pre><code>## [1] 232 204 612 1272 462</code></pre>
<pre><code>## [1] 322 1772 682 261 782</code></pre>
<hr />
</div>
<div id="error-unexpected-in-error-unexpected-in-error-unexpected-x-in" class="section level2">
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ <h2>Testimonials from our other courses:</h2>
<h2>Find an Error!?</h2>
<hr />
<p>Feel free to submit typos/errors/etc via the GitHub repository associated with the class: <a href="https://github.com/fhdsl/DaSEH" class="uri">https://github.com/fhdsl/DaSEH</a></p>
<p>This page was last updated on 2024-10-09.</p>
<p>This page was last updated on 2024-10-10.</p>
<p style="text-align:center;">
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://live.staticflickr.com/4557/26350808799_6f9c8bcaa2_b.jpg" height="150"/> </a>
</p>
Expand Down
3,918 changes: 345 additions & 3,573 deletions modules/Functions/Functions.html

Large diffs are not rendered by default.

63 changes: 38 additions & 25 deletions modules/Functions/lab/Functions_Lab.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,34 @@ knitr::opts_chunk$set(echo = TRUE)

# Part 1

Load all the libraries we will use in this lab.
Load the `tidyverse` package.

```{r message=FALSE}
library(tidyverse)
```

### 1.1

Create a function that takes one argument, a vector, and returns the sum of the vector and then squares the result. Call it "sum_squared". Test your function on the vector `c(2,7,21,30,90)` - you should get the answer 22500.
Create a function that:

```
# General format
NEW_FUNCTION <- function(x, y) x + y
```
or

```
# General format
NEW_FUNCTION <- function(x, y){
result <- x + y
return(result)
}
```
* Takes one argument, a vector.
* Returns the sum of the vector and then squares the result.
* Call it "sum_squared".
* Test your function on the vector `c(2,7,21,30,90)` - you should get the answer 22500.
* Format is `NEW_FUNCTION <- function(x, y) x + y`

```{r 1.1response}
```

### 1.2

Create a function that takes two arguments, (1) a vector and (2) a numeric value. This function tests whether the number (2) is contained within the vector (1). **Hint**: use `%in%`. Call it `has_n`. Test your function on the vector `c(2,7,21,30,90)` and number `21` - you should get the answer TRUE.
Create a function that:

* takes two arguments, (1) a vector and (2) a numeric value.
* This function tests whether the number (2) is contained within the vector (1). **Hint**: use `%in%`.
* Call it `has_n`.
* Test your function on the vector `c(2,7,21,30,90)` and number `21` - you should get the answer TRUE.

```{r 1.2response}
Expand All @@ -57,7 +54,13 @@ Amend the function `has_n` from question 1.2 so that it takes a default value of

### P.1

Create a new number `b_num` that is not contained with `nums`. Use your updated `has_n` function with the default value and add `b_num` as the `n` argument when calling the function. What is the outcome?
Create a function for the CalEnviroScreen Data.

* Read in (https://daseh.org/data/CalEnviroScreen_data.csv)
* The function takes an argument for a column name. (use `{{col_name}}`)
* The function creates a ggplot with `{{col_name}}` on the x-axis and `Poverty` on the y-axis.
* Use `geom_point()`
* Test the function using the `Lead` column and `HousingBurden` columns, or other columns of your choice.

```{r P.1response}
Expand All @@ -76,7 +79,12 @@ Read in the CalEnviroScreen from https://daseh.org/data/CalEnviroScreen_data.csv

### 2.2

We want to get some summary statistics on water contamination. Use `across` inside `summarize` to get the sum total variable containing the string "water" AND ending with "Pctl". **Hint**: use `contains()` AND `ends_with()` to select the right columns inside `across`. Remember that `NA` values can influence calculations.
We want to get some summary statistics on water contamination.

* Use `across` inside `summarize`.
* Choose columns about "water". **Hint**: use `contains("water")` inside `across`.
* Use `mean` as the function inside of `across`.
* Remember that `NA` values can influence calculations.

```
# General format
Expand All @@ -93,7 +101,12 @@ data %>%

### 2.3

Use `across` and `mutate` to convert all columns containing the word "water" into proportions (i.e., divide that value by 100). **Hint**: use `contains()` to select the right columns within `across()`. Use an anonymous function ("function on the fly") to divide by 100 (`function(x) x / 100`). It will also be easier to check your work if you `select()` columns that match "Pctl".
Convert all columns that are percentiles into proportions.

* Use `across` and `mutate`
* Choose columns that contain "Pctl" in the name. **Hint**: use `contains("Pctl")` inside `across`.
* Use an anonymous function ("function on the fly") to divide by 100 (`function(x) x / 100`).
* Check your work - It will also be easier if you `select(contains("Pctl"))`.

```
# General format
Expand All @@ -115,9 +128,9 @@ data %>%

Use `across` and `mutate` to convert all columns starting with the string "PM" into a binary variable: TRUE if the value is greater than 10 and FALSE if less than or equal to 10.

- **Hint**: use `starts_with()` to select the columns that start with "PM".
- Use an anonymous function ("function on the fly") to do a logical test if the value is greater than 10.
- A logical test with `mutate` will automatically fill a column with TRUE/FALSE.
* **Hint**: use `starts_with()` to select the columns that start with "PM".
* Use an anonymous function ("function on the fly") to do a logical test if the value is greater than 10.
* A logical test with `mutate` (x > 10) will automatically fill a column with TRUE/FALSE.

```{r P.2response}
Expand All @@ -127,9 +140,9 @@ Use `across` and `mutate` to convert all columns starting with the string "PM" i

Take your code from previous question and assign it to the variable `ces_dat`.

- Use `filter()` to drop any rows where "Oakland" appears in `ApproxLocation`. Make sure to reassign this to `ces_dat`.
- Create a ggplot boxplot (`geom_boxplot()`) where (1) the x-axis is `Asthma` and (2) the y-axis is `PM2.5`.
- You change the `labs()` layer so that the x-axis is "ER Visits for Asthma: PM2.5 greater than 10"
- Create a ggplot where the x-axis is `Asthma` and the y-axis is `PM2.5`.
- Add a boxplot (`geom_boxplot()`)
- Change the `labs()` layer so that the x-axis is "ER Visits for Asthma: PM2.5 greater than 10"

```{r P.3response}
Expand Down
259 changes: 182 additions & 77 deletions modules/Functions/lab/Functions_Lab_Key.html

Large diffs are not rendered by default.

0 comments on commit 72f52a8

Please sign in to comment.