Skip to content

Commit

Permalink
Added step to update mmash.R summarise calls (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
lwjohnst86 authored May 5, 2024
2 parents 9fb858c + 3dc1bfb commit 06761cf
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions sessions/dplyr-joins.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,49 @@ library(fs)
source(here("R/functions.R"))
```

Making sure to have the `download.file()` commented out, we'll include
some code to delete the created `data-raw/mmash/` folder so this script
can run cleanly each time. Place the code right below where the
`download.file()` code is.

<!-- TODO: Remove this after course ends, since the same info is in pre-course now -->

```{r data-raw-mmash-comment-out}
#| filename: "data-raw/mmash.R"
#| eval: false
# Download
mmash_link <- "https://physionet.org/static/published-projects/mmash/multilevel-monitoring-of-activity-and-sleep-in-healthy-people-1.0.0.zip"
# download.file(mmash_link, destfile = here("data-raw/mmash-data.zip"))
# Remove previous `mmash/` folder to have clean update
dir_delete(here("data-raw/mmash/"))
```

Next, as we have altered `import_multiple_files()` to use
`file_path` instead of `file_path_id`, we'll need to update how we
`group_by()` when creating `summarised_rr_df` and
`summarised_actigraph_df`.

```{r data-raw-mmash-update}
#| filename: "data-raw/mmash.R"
summarised_rr_df <- rr_df |>
group_by(user_id, day) |>
summarise(across(ibi_s, list(
mean = \(x) mean(x, na.rm = TRUE),
sd = \(x) sd(x, na.rm = TRUE)
))) |>
ungroup()
summarised_actigraph_df <- actigraph_df |>
group_by(user_id, day) |>
summarise(across(hr, list(
mean = \(x) mean(x, na.rm = TRUE),
sd = \(x) sd(x, na.rm = TRUE)
))) |>
ungroup()
reduce(full_join)
```

Go into the `doc/learning.qmd` and cut the code used to create the
`saliva_with_day_df` as well as the code to `full_join()` all the
datasets together with `reduce()` and paste it at the bottom of the
Expand Down

0 comments on commit 06761cf

Please sign in to comment.