Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- agg <- aggregate(Valor ~ Filial, dados, sum)
- agg$Contagem <- tapply(dados$Filial, dados$Filial, FUN = length)
- agg <- agg[, c(1, 3, 2)]
- agg
- # Filial Contagem Valor
- #1 ABC 2 1512
- #2 JCT 2 610
- #3 XYZ 2 1170
- dados <-
- structure(list(Filial = structure(c(1L, 3L, 3L, 2L, 2L, 1L), .Label = c("ABC",
- "JCT", "XYZ"), class = "factor"), Matrícula = c(100L, 200L, 100L,
- 300L, 300L, 300L), Valor = c(500, 850, 320, 512, 98, 1012)), .Names = c("Filial",
- "Matrícula", "Valor"), class = "data.frame", row.names = c(NA,
- -6L))
Add Comment
Please, Sign In to add comment