Aggregate function in R

Asked

Viewed 68 times

0

Good afternoon. I am using the function aggregate to group some data. However, I am only using one variable to add up. I would like to use more than one variable. Is this possible? I am using the following example:

TESTE = aggregate(VALOR ~ REFERENCIA + GRUPO_COPA + CIDADE, data=DADOS,FUN=sum)

I would like to use variable QTDE next to VALOR to add, that is, add one more column, with the following columns: REFERENCIA, GRUPO_COPA, CIDADE, VALOR, QTDE It is possible in the aggregate or in another function this example? Grateful

Here’s my example using dput(DADOS):

structure(list(REFERENCIA = c("JAN_2017", "JAN_2017", "JAN_2017", "JAN_2017", "FEV_2017", "FEV_2017", "FEV_2017", "FEV_2017", "FEV_2017" ), GRUPO_COPA = c("AZUL", "AZUL", "AMARELO", "AMARELO", "VERDE", "VERDE", "VERDE", "AZUL", "AZUL"), CIDADE = c("SP", "SP", "SP", "SP", "RJ", "BSB", "BSB", "BSB", "SP"), VALOR = c(1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000), QTDE = c(1, 3, 5, 7, 9, 11, 13, 15, 17)), .Names = c("REFERENCIA", "GRUPO_COPA", "CIDADE", "VALOR", "QTDE"), row.names = c(NA, 9L), class = "data.frame")
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.