-3

I'm trying to sum all of the similar Date/time rows into one row and a "count" row. Therefore I'll get two columns- one for the Date/Time and one for the count. I used this argument to round my observations into a 15 minute time period: dat$by15 <- cut(dat$Date_Time, breaks = "15 min", )

I tried to use this argument, but it's "jumping" to a previous dataset and giving me the wrong observations for some reason:

dat <- aggregate(dat, by = list(dat$by15), length )

Thank you guys !

  • 2
    Welcome to StackOverflow! Please read the info about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to give a [reproducible example](http://stackoverflow.com/questions/5963269). This will make it much easier for others to help you. – Ronak Shah Jan 22 '19 at 14:51
  • You need to use `ave` i.e. `with(dat, ave(seq_along(by15), by15, FUN = length))` – akrun Jan 22 '19 at 14:52
  • 1
    Please do not post an image of code/data/errors: it cannot be copied or searched (SEO), it breaks screen-readers, and it may not fit well on some mobile devices. Ref: https://meta.stackoverflow.com/a/285557/3358272. – r2evans Jan 22 '19 at 15:08

1 Answers1

0

I'm not sure if I understood the question, but if you are trying to group by date and count observations for each date it's really simple

library(dplyr)

grouped_dates <- dat %>% 
  group_by(Date_Time) %>%
  summarise(Count = n())
Ric S
  • 9,073
  • 3
  • 25
  • 51
  • Thanks for the help, but as the same as the argument I wrote the output that I get when running it is : by15 count 2014-06-01 00:00:00 12 2014-06-01 00:00:15 10 2014-06-01 00:00:30 7 . . . When the original data is : by15 2014-06-01 00:00:00 2014-06-01 00:00:00 2014-06-01 00:03:30 2014-06-01 00:06:45 – Omer Mishpati Jan 22 '19 at 22:06