Hi, and welcome!
Please see the FAQ: What's a reproducible example (`reprex`) and how do I do one? Using a reprex, complete with representative data will attract quicker and more answers. You've done a good job here, just missing a bit.
The most pressing issue is the y argument to SummarizeFn
, Price
. It's not in the namespace because it's embedded in df
.
The simplest fix to that part of the problem is using df$price as the y argument
suppressPackageStartupMessages(library(dplyr))
df <- data.frame("Treatment" = c(rep("A", 2), rep("B", 2)), "Price" = 1:4, "Cost" = 2:5)
SummarizeFn <- function(x,y) {
x %>% group_by(Treatment) %>%
summarize(
n = n(),
Mean = mean(y),
SD = sd(y)
) %>% cbind ("Var" = rep(y, 3)) # add a column to show which variable those statistics belong to.
}
SumPrice <- SummarizeFn(df, df$Price)
SumPrice
#> Treatment n Mean SD Var
#> 1 A 2 2.5 1.290994 1
#> 2 B 2 2.5 1.290994 2
#> 3 A 2 2.5 1.290994 3
#> 4 B 2 2.5 1.290994 4
#> 5 A 2 2.5 1.290994 1
#> 6 B 2 2.5 1.290994 2
#> 7 A 2 2.5 1.290994 3
#> 8 B 2 2.5 1.290994 4
#> 9 A 2 2.5 1.290994 1
#> 10 B 2 2.5 1.290994 2
#> 11 A 2 2.5 1.290994 3
#> 12 B 2 2.5 1.290994 4
Created on 2020-03-30 by the reprex package (v0.3.0)