From 6d7f90d7957419c29079f2f458990dc45ebf12ec Mon Sep 17 00:00:00 2001 From: carriewright11 Date: Mon, 8 Jun 2026 16:24:13 -0600 Subject: [PATCH 1/6] fix typo --- modules/Data_Cleaning/Data_Cleaning.Rmd | 7 ------- 1 file changed, 7 deletions(-) diff --git a/modules/Data_Cleaning/Data_Cleaning.Rmd b/modules/Data_Cleaning/Data_Cleaning.Rmd index 872477ce..ecafda55 100644 --- a/modules/Data_Cleaning/Data_Cleaning.Rmd +++ b/modules/Data_Cleaning/Data_Cleaning.Rmd @@ -440,13 +440,6 @@ plastics |> Using Excel to find all of the different ways `microplastic` has been coded, could be hectic! In `dplyr` you can use the `case_when` function. - -## Or you can use `case_when()` - -The `case_when()` function of `dplyr` can help us to do this as well. - -It is more flexible and powerful. - ::: {style="color: red;"} (need `mutate` here too!) ::: From d58ba70e243aeda61e36d540323e566b60e220b2 Mon Sep 17 00:00:00 2001 From: carriewright11 Date: Mon, 8 Jun 2026 16:28:38 -0600 Subject: [PATCH 2/6] adding another note --- modules/Data_Cleaning/Data_Cleaning.Rmd | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/Data_Cleaning/Data_Cleaning.Rmd b/modules/Data_Cleaning/Data_Cleaning.Rmd index ecafda55..5b01d23e 100644 --- a/modules/Data_Cleaning/Data_Cleaning.Rmd +++ b/modules/Data_Cleaning/Data_Cleaning.Rmd @@ -593,6 +593,7 @@ head(plastics) plastics |> count(Foods, Effect) ``` + ## Note that if you change data classes this might impact .default ```{r, eval = FALSE} @@ -601,7 +602,7 @@ plastics <- plastics |> blood_level_change_nM > 0 ~ "Increase", blood_level_change_nM == 0 ~ "Same", blood_level_change_nM < 0 ~ "Decrease", - .default = blood_level_change_nM)) + .default = blood_level_change_nM)) #default is class double # this will give an error! plastics <- plastics |> From e9b17019ed9f02763c09d40e8951847c4fa8a33a Mon Sep 17 00:00:00 2001 From: carriewright11 Date: Mon, 8 Jun 2026 16:30:17 -0600 Subject: [PATCH 3/6] adding another note --- modules/Data_Cleaning/Data_Cleaning.Rmd | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/Data_Cleaning/Data_Cleaning.Rmd b/modules/Data_Cleaning/Data_Cleaning.Rmd index 5b01d23e..f6413765 100644 --- a/modules/Data_Cleaning/Data_Cleaning.Rmd +++ b/modules/Data_Cleaning/Data_Cleaning.Rmd @@ -597,6 +597,9 @@ plastics |> ## Note that if you change data classes this might impact .default ```{r, eval = FALSE} + +class(pull(plastics, blood_level_change_nM)) + plastics <- plastics |> mutate(Effect = case_when( blood_level_change_nM > 0 ~ "Increase", From 846924ff0ba294b293e08cd5ec8725fa5362414b Mon Sep 17 00:00:00 2001 From: carriewright11 Date: Mon, 8 Jun 2026 16:34:15 -0600 Subject: [PATCH 4/6] make a few slides smaller --- modules/Data_Cleaning/Data_Cleaning.Rmd | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/Data_Cleaning/Data_Cleaning.Rmd b/modules/Data_Cleaning/Data_Cleaning.Rmd index f6413765..95c79187 100644 --- a/modules/Data_Cleaning/Data_Cleaning.Rmd +++ b/modules/Data_Cleaning/Data_Cleaning.Rmd @@ -476,7 +476,7 @@ plastics |> ``` -## `case_when()` drops unspecified values +## `case_when()` drops unspecified values{.codesmall} Note that automatically values not reassigned explicitly by `case_when()` will be `NA` unless otherwise specified. @@ -619,7 +619,7 @@ plastics <- plastics |> ``` -## multiple conditions with `case_when` recoding +## multiple conditions with `case_when` recoding{.codesmall} ```{r} plastics |> @@ -857,7 +857,7 @@ head(plastics_comb) head(plastics_comb) |> n_complete_row() ``` -## `recode()` function +## `recode()` function{.codesmall} This is similar to `case_when()` but it can't do as much. From b934f1c8bce4f1e03eb1dd14c9fcd7db87c5f902 Mon Sep 17 00:00:00 2001 From: carriewright11 Date: Mon, 8 Jun 2026 16:40:25 -0600 Subject: [PATCH 5/6] fix fitting on slide for output --- modules/Data_Cleaning/Data_Cleaning.Rmd | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/modules/Data_Cleaning/Data_Cleaning.Rmd b/modules/Data_Cleaning/Data_Cleaning.Rmd index 95c79187..d6562318 100644 --- a/modules/Data_Cleaning/Data_Cleaning.Rmd +++ b/modules/Data_Cleaning/Data_Cleaning.Rmd @@ -605,7 +605,8 @@ plastics <- plastics |> blood_level_change_nM > 0 ~ "Increase", blood_level_change_nM == 0 ~ "Same", blood_level_change_nM < 0 ~ "Decrease", - .default = blood_level_change_nM)) #default is class double + .default = blood_level_change_nM)) +#default is class double # this will give an error! plastics <- plastics |> @@ -621,7 +622,17 @@ plastics <- plastics |> ## multiple conditions with `case_when` recoding{.codesmall} -```{r} +```{r, eval = FALSE} +plastics |> + mutate(Amt_change = case_when( + blood_level_change_nM > 0 & blood_level_change_nM < 2 ~ "Small", + blood_level_change_nM >= 2 ~ "Large", + blood_level_change_nM < 0 & blood_level_change_nM > -2 ~ "Small", + blood_level_change_nM <= -2 ~ "Large", + blood_level_change_nM == 0 ~ "none")) +``` + +```{r, echo=FALSE} plastics |> mutate(Amt_change = case_when( blood_level_change_nM > 0 & blood_level_change_nM < 2 ~ "Small", @@ -629,7 +640,7 @@ plastics |> blood_level_change_nM < 0 & blood_level_change_nM > -2 ~ "Small", blood_level_change_nM <= -2 ~ "Large", blood_level_change_nM == 0 ~ "none")) |> - head() + print(n = 6, width = Inf) ``` ## GUT CHECK: we need to use what function with `case_when()` to modify or create a new variable? From 51a714d26214cedb0e839043033963b7ddf6bd37 Mon Sep 17 00:00:00 2001 From: carriewright11 Date: Mon, 8 Jun 2026 16:41:23 -0600 Subject: [PATCH 6/6] fixing title of slide --- modules/Data_Cleaning/Data_Cleaning.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/Data_Cleaning/Data_Cleaning.Rmd b/modules/Data_Cleaning/Data_Cleaning.Rmd index d6562318..0525af0e 100644 --- a/modules/Data_Cleaning/Data_Cleaning.Rmd +++ b/modules/Data_Cleaning/Data_Cleaning.Rmd @@ -709,7 +709,7 @@ The `replacement` argument specifies what to replace the pattern with str_replace(string = Effect, pattern = "D", replacement = "d") ``` -## `st_replace()` only replaces the first instance of the pattern in each value +## `str_replace()` only replaces the first instance of the pattern in each value `str_replace_all()` can be used to replace all instances within each value