4
Good afternoon.
I’m 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
Is it possible in Aggregate or other function this example? Grateful.
Edit
Check out my example using dput (DATA):
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")
I would like you to group this dataset (similar to Aggregate or similar) together by adding the columns VALUE and QTDE.
A tip: it is much easier to get help here by providing a data set. It is not necessary to be your complete original set. It can only be a part of it. To share your dataset, run
dput(DADOS)
and paste the result into the body of the question.– Marcus Nunes