-4

I have a data frame that I am trying to condense. There are multiple value os X with the same names but with different Y values associated with them:

  X Y
1 a 1
2 b 3
3 a 2
4 c 4
5 b 7

I want to condense the data frame so there are no duplicate names in X, like below:

  X Y
1 a 3
2 b 10
3 c 4
Kevin Arseneau
  • 6,186
  • 1
  • 21
  • 40
Colin
  • 47
  • 3

1 Answers1

0

Using tidyverse:

library(tidyverse)
df <- df %>%
group_by(x) %>%
summarise(y = sum(y))
Pete
  • 600
  • 1
  • 6
  • 16