I have some data that consists in 3 response variables divided in 3 groups tested in several batches . e.g:
Batch    Type    Replicate    Y1     Y2    Y3
1         A        a           200    100   80
I need to extract the variances for that I build a function:
My_function <- function(x) {
  md_mm <- lmer(Y1 ~ (1|Batch), data = x) 
  tab_mm <- summary(md_mm)
  tab2_mm <- as.data.frame(tab_mm$varcor)
  m <- mean(x$Y1,na.rm=TRUE)
  BatchVar <-tab2_mm[1,4]
  ReptVar <- tab2_mm[2,4]
  df_mm <- data.frame(m,BatchVar, ReptVar)
  return(df_mm)
}
and then I use it:
    table <- df %>% 
  group_by(Type) %>% 
  do(My_function(.)) %>% 
  as.data.frame()
So far this works, but I have been trying to change it so I can get it so the table includes the results for all the variables. I tried with a function with My_function(x,y) and then map() so it runs on all the variables and it works if I tried with the whole variable, when I try to group it then if goes wrong. If anyone has an idea that could help, it would be very much appreciated. Thanks,
 
    