0

I have this datatable:

date, sentiment, price
2015-09-05, 1, 200
2015-09-05, 2, 200
2015-09-06, 1, 300

I would like to get a new datatable with the sum of the sentiment per day, keeping the daily price

I tried to do this:

new_dt <- dt%>%
  select(date, sentiment, price)%>%
  filter(date > "2015-09-05" & date <"2015-09-06")
  group_by(date)

expected output:

date, sentiment, price
2015-09-05, 3, 200
2015-09-06, 1, 300
Frank
  • 66,179
  • 8
  • 96
  • 180
HABLOH
  • 460
  • 2
  • 12
  • 4
    After the `group_by(date) %>% summarise(price = first(price), sentiment = sum(sentiment))` – akrun Jun 04 '19 at 15:08

1 Answers1

2

Use the summarise() function to get summary statistics:

new_dt <- dt%>%
  select(date, sentiment, price)%>%
  filter(date > "2015-09-05" & date <"2015-09-06")
  group_by(date) %>%
  summarise(sentiment=sum(sentiment),price=sum(price))

For price, you could use max(), min() etc depending on what you want.

Lisa Clark
  • 340
  • 1
  • 2
  • 11