brad-cannell / bfuncs

A random smattering of Brad's Functions
MIT License
2 stars 0 forks source link

mean_table can't call a variable "x" #36

Open mbcann01 opened 6 years ago

mbcann01 commented 6 years ago

This doesn't work:

library(tidyverse)
library(bfuncs)

df <- tibble(
  g = c(rep("a", 5000), rep("b", 5000)),
  x = runif(10000, 0, 100)
)

df %>% group_by(g) %>% bfuncs::mean_table(x)

Error in summarise_impl(.data, dots) : 
  Evaluation error: `expr` must quote a symbol, scalar, or call. 

But this does work:

df <- tibble(
  g = c(rep("a", 5000), rep("b", 5000)),
  a = runif(10000, 0, 100)
)

df %>% group_by(g) %>% bfuncs::mean_table(a)
mbcann01 commented 5 years ago

Also, can't call variable "n"

This doesn't work:

aps_its %>% 
  group_by(study_week, group) %>% 
  summarise(n = n()) %>% 
  group_by(group) %>% 
  mean_table(n)

But, this does:

aps_its %>% 
  group_by(study_week, group) %>% 
  summarise(n = n()) %>% 
  group_by(group) %>% 
  mutate(count = n) %>% 
  mean_table(count)