I'd like to write a function that calculate a mean of a given variable with using dplyr function. I tried following concept with many modifications but were not succesful. Should one avoid dplyr
functions within own functions? or is there any trick that do the thing?
df <- data.frame(type = c("KL", "KL", "A", "A", "B", "B"),
D10 = rnorm(6, 3, 4))
licz <- function(dat, trait){
require("dplyr")
dat %>% group_by_(type) %>% summarise(sr = mean(trait, na.rm = T)) -> dataset
return(dataset)
}
licz(df, D10)