-1

I have a dataset with time, where the time intervals are 6 hours apart and I have a column of heaterstatus. The dataset :

enter image description here

I would like to know the percentage of zero occurred in each day for heaterstatus. New to R, any suggestion will be helpful.

  • Hi @Notslayer205, please provide your data in a copy-paste able form using `dput()`, [not as an image](https://meta.stackoverflow.com/a/285557/17303805). See [How to make a great R reproducible example](https://stackoverflow.com/q/5963269/17303805) for more details on how to ask an effective R question on Stack Overflow. Thanks! – zephryl Feb 03 '23 at 03:08
  • Does this answer your question? [Relative frequencies / proportions with dplyr](https://stackoverflow.com/questions/24576515/relative-frequencies-proportions-with-dplyr) – Edward Feb 03 '23 at 03:21

1 Answers1

1

Not tested since you only provided data as an image, but this should do what you want:

library(dplyr)

dat %>%
  group_by(day = as.Date(Time)) %>%
  summarize(pct_0 = mean(HeaterStatus == 0))
zephryl
  • 14,633
  • 3
  • 11
  • 30
  • 1
    Generally I think this is the way to go, but you'd have to be careful with `as.Date(Time)` as it can cause issues with timezone conversions e.g.: https://stackoverflow.com/questions/17098862/as-dateas-posixct-gives-the-wrong-date/17099360 – thelatemail Feb 03 '23 at 04:22