close / Compute_YEI.R
pajuan's picture
Upload 3 files
9493ec9 verified
#
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()