From ffc09e75977aabe362ba07fbf89c8cbdb0beb18b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 10 Oct 2024 14:23:42 +0000 Subject: [PATCH] Render site --- help.html | 8 ++-- modules/Functions/lab/Functions_Lab.html | 60 +++++++++++++++++------- 2 files changed, 46 insertions(+), 22 deletions(-) diff --git a/help.html b/help.html index 8b8d2685..41f4951b 100644 --- a/help.html +++ b/help.html @@ -353,14 +353,14 @@

Why are my changes not taking effect? It’s making my results look

Here we are creating a new object from an existing one:

new_rivers <- sample(rivers, 5)
 new_rivers
-
## [1]  320 1770  680  259  780
+
## [1]  618  720  625  425 1270

Using just this will only print the result and not actually change new_rivers:

new_rivers + 1
-
## [1]  321 1771  681  260  781
+
## [1]  619  721  626  426 1271

If we want to modify new_rivers and save that modified version, then we need to reassign new_rivers like so:

new_rivers <- new_rivers + 1
 new_rivers
-
## [1]  321 1771  681  260  781
+
## [1]  619  721  626  426 1271

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.


@@ -409,7 +409,7 @@

Error: object ‘X’ not found

Make sure you run something like this, with the <- operator:

rivers2 <- new_rivers + 1
 rivers2
-
## [1]  322 1772  682  261  782
+
## [1]  620  722  627  427 1272

diff --git a/modules/Functions/lab/Functions_Lab.html b/modules/Functions/lab/Functions_Lab.html index e477c8c7..3464ae97 100644 --- a/modules/Functions/lab/Functions_Lab.html +++ b/modules/Functions/lab/Functions_Lab.html @@ -167,23 +167,28 @@

Functions Lab

Part 1

-

Load all the libraries we will use in this lab.

+

Load the tidyverse package.

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.

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

or

-
# General format
-NEW_FUNCTION <- function(x, y){
-result <- x + y
-return(result)
-}
+

Create a function that:

+
    +
  • 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
  • +

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.
  • +

1.3

@@ -191,7 +196,14 @@

1.3

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.
  • +
@@ -202,7 +214,13 @@

2.1

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
 data %>%
   summarize(across(
@@ -212,7 +230,13 @@ 

2.2

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
 data %>%
   mutate(across(
@@ -229,16 +253,16 @@ 

P.2

  • 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.
  • +
  • A logical test with mutate (x > 10) will automatically fill a column with TRUE/FALSE.

P.3

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”