Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
lwjohnst86 committed May 5, 2024
2 parents c0476b1 + 06761cf commit 3fc05b0
Showing 1 changed file with 45 additions and 2 deletions.
47 changes: 45 additions & 2 deletions sessions/dplyr-joins.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ saliva_with_day_df
#| filename: "doc/learning.qmd"
list(
user_info_df,
saliva_df,
saliva_with_day_df,
summarised_rr_df,
summarised_actigraph_df
) |>
Expand Down 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 All @@ -646,7 +689,7 @@ saliva_with_day_df <- saliva_df |>
mmash <- list(
user_info_df,
saliva_df,
saliva_with_day_df,
summarised_rr_df,
summarised_actigraph_df
) |>
Expand Down

0 comments on commit 3fc05b0

Please sign in to comment.