Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.3.6 tidyverse parallel for the transformed base R #52

Open
ukleiner opened this issue Apr 4, 2024 · 0 comments
Open

4.3.6 tidyverse parallel for the transformed base R #52

ukleiner opened this issue Apr 4, 2024 · 0 comments

Comments

@ukleiner
Copy link

ukleiner commented Apr 4, 2024

In section 4.3.6 the base R version t(apply(post[, 1:2], 2, quantile, probs = c(.5, .025, .75))) doesn't have a parallel tidyverse version.
One can use a solution like this:

post %>%
  select(b_Intercept, sigma) %>%
  reframe(qs = c(.5, .025, 0.75), across(.cols=c(b_Intercept, sigma), .fns=~quantile(.x, probs=qs)))

The existing tidyverse code uses a superseded function mutate_if the code can be updated to (only the mutate function changes)

post %>%
  pivot_longer(b_Intercept:sigma) %>% 
  group_by(name) %>%
  summarise(mean = mean(value),
            sd   = sd(value),
            `2.5%`  = quantile(value, probs = .025),
            `97.5%` = quantile(value, probs = .975)) %>%
  mutate(across(.cols=is.numeric, .fns=~round(.x, digits = 2)))

Thanks for an excellent book!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant