I have two different questions:
1.
toy <-
tribble(
~subj_id, ~resp, ~mean1, ~mean2, ~mean3, ~mean4, ~mean5,
"subj1", "banana", 2.2, .90, 1.3, 7.99, .031,
"subj1", "orange sherbert", 4.4, 2.9, 5.5, 2.9, 4.1,
"subj1", "tiger", 1.2, 4.90, 1.25, 3.99, 2.0,
"subj2", "tiger", 3.2, 0.90, 1.30, 3.99, 2.0,
"subj2", "animal", 1.7, 2.90, 3.3, 2.19, 5.0,
"subj2", "orange paint", 3.15, 2.49, 0.98, 1.88, 2.4,
"subj3", "orange crayon", 3.16, 2.78, 1.98, 0.88, 1.4,
"subj3", "wax", 1.75, 2.40, 3.3, 2.17, 5.0,
"subj3", "crossfit", 1.9, 3.29, 4.80, 1.98, 4.5,
"subj4", "obstacle course", 1.66, 2.90, 3.3, 1.75, 4.0,
"subj4", "boot camp", 2.75, 3.40, 1.3, 3.17, 2.75,
"subj5", "orange", 4.9, 3.8, 2.88, 3.75, 4.25,
"subj5", "granny smith", 1.16, 2.3, 2.75, 4.8, 3.5
)
ranks <- toy %>%
mutate(across(contains("mean"), list(rank = ~ percent_rank(.x))),
top_10_per = pmap_dbl(across(contains("rank")), ~sum(c(...) > .9)),
best_rank = pmap_dbl(across(contains("rank")), max))
I would like to understand what does:
~sum(c(...)
it do ? What is hiding behind (...) - I mean what kind of arguments ?
- This is probably about programming with dplyr:
df = tibble(x=1:5, p1=x*2, p2=x*4, p3=x*5)
library(tidyverse)
f = function(x, y) {
x2=x
tibble(!!paste0(y, '_inf') := x2-10,
!!paste0(y, '_sup') := x2+10)
}
imap_dfc(select(df, starts_with('p')), f)
I am particularly interested in the following part:
tibble(!!paste0(y, '_inf') := x2-10,
!!paste0(y, '_sup') := x2+10)
Why !! have been used here ? What := is doing here ?
Much obliged for help with understanding these things, thank you.