a = tibble(x = runif(1000,0,10),
t = rpois(1000,4),
s = sample(c(0,1),1000, replace = T)
) %>% group_by(t)
I want to summarise
twice mean(x)
in a
.
First variable b1
is mean(x)
when s == 0
Second variable b2
is mean(x)
when s == 1
Which is the fastest way within a summarise?
Important: I don't want to group_by(s)
, which is probably the fastest option... the output would be confusing.