0

I am new to R can't find the right syntax for a specific average I need. I have a large fitbit dataset of heartrate per second for 30 people, for a month each. I want an average of heartrate per day per person to make the data easier to manage and join with other fitbit data.

First few lines of Data

The columns I have are Id (person Id#), Time (Date-Time), and Value (Heartrate). I already separated Time into two columns, one for date and one for time only. My idea is to group the information by person, then by date and get one average number per person per day. But, my code is not doing that.

hr_avg <- hr_per_second %>% group_by(Id) %>% group_by(Date) %>% summarize(mean(Value))

As a result I get an average by date only. I can't do this manually because the dataset is so big, Excel can't open it. And I can't upload it to BigQuery either, the database I learned to use during my data analysis course. Thanks.

  • 3
    try `group_by(Id, date)`, with `group_by(Id) %>% group_by(Date)` you override the first grouping – shs Aug 05 '22 at 20:08
  • Welcome to StackOverflow. Thanks for showing the code. Instead of images of data, you can use `dput(head(nameofyourdataobjectinR))` to provide a sample of the data. You can also look at this for more information on writing good questions: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – John Polo Aug 05 '22 at 20:17
  • @shs Thank You! that solved my problem. Such an easy fix. – Stephanie Perez Aug 05 '22 at 21:30

0 Answers0