0
 Symbol       Date           Value   
 A            2017-01-06     10
 B            2017-01-09     11
 C            2017-01-10      5
 D            2017-01-10      5
 E            2017-01-12     12 
 F            2017-01-13     14

Here is my data, I have sometimes the same Date, here 2017-01-10 and I would like to sum the Value and to keep only a single Date For exemple it should look like this

  Symbol       Date           Value   
     A            2017-01-06     10
     B            2017-01-09     11
     C            2017-01-10     10   
     E            2017-01-12     12 
     F            2017-01-13     14

Thanks

nico dm
  • 19
  • 3

1 Answers1

0

We can use dplyr

library(dplyr)
df1 %>%
  group_by(Date) %>%
  summarise(Symbol= first(Symbol), Value = sum(Value)) %>%
  select(Symbol, Date, Value)
# A tibble: 5 x 3
#  Symbol Date       Value
#  <chr>  <chr>      <int>
#1 A      2017-01-06    10
#2 B      2017-01-09    11
#3 C      2017-01-10    10
#4 E      2017-01-12    12
#5 F      2017-01-13    14
akrun
  • 874,273
  • 37
  • 540
  • 662