|
|
|
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")
|
|
)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|