How to group data in R?

Asked

Viewed 46 times

2

I wonder if it has any function in the R that makes it possible to make a kind of "grouping" of the data. For example, a way to get this spreadsheet to return something like:

Codigo   Grupo  Qtde  Total 
  3219  Vacina     3    293 

Thanks in advance!

inserir a descrição da imagem aqui

Test data:

dados <- data.frame(Codigo = c(3219, 3219, 3219, 3865, 3865, 3865),
                    Grupo = c('Vacina','Vacina','Vacina','Estética','Clínico','Clínico'),
                    Qtde = c(1, 1, 1, 19, 1, 1),
                    Total = c(58.00, 160.00, 75.00, 760.00, 170.00, 0.01))
  • 1

    Beatriz, good night! You can use the dplyr group_by: dados %>% group_by(Codigo, Grupo)%>%&#xA; summarise(Qtde = sum(Qtde, na.rm = T), Total = sum(Total, na.rm = T))

  • 2

    Perfect @lmonferrari’s answer. I just didn’t understand why the question was flagged out of scope. It’s probably a duplicate question...

  • 1

    @Luizz For example, this question.

  • Yes, that’s what I figured, @Rui. It’s a common question. That’s why I thought it should be flagged as duplicate, not as out of scope. Not to give the wrong signage to new users. But I do not know, it is only my opinion

No answers

Browser other questions tagged

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