File size: 1,312 Bytes
9493ec9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
#
inspecciones.GROUP_BY.compute_yei=function(inspecciones,
GROUP_BY=c(
"ano" ,
"mes",
"CLASIFICAC",
"NOM_VULGAR"
)){
#
inspecciones %>%
dplyr::mutate(
groups=inspecciones %>%
dplyr::select(GROUP_BY) %>%
apply(MARGIN = 1, FUN=function(row){
paste(row, collapse=".")
})
) %>%
split(.$groups) %>%
lapply(function(sub_df){
new_df=
data.frame(
yei=sum(sub_df$CT_KG)
)
for (groupping_factor in GROUP_BY){
new_df[[groupping_factor]]=dplyr::first(sub_df[[groupping_factor]])
}
new_df
}) %>%
bind_rows() %>%
Dataframe.order(
setdiff(names(.), "yei")
)
}
# upstream
#
# inspecciones %>%
# inspecciones.activas() %>%
# inspecciones.ensamblar_variables_de_reporte() %>%
# #
# # under test
# #
# inspecciones.GROUP_BY.compute_yei() %>%
# #
# # downstream
# #
# tabla_de_reporte.formatear_ciclo_anual_en_columnas() %>%
# View()
|