Average by week

I am trying to calculate the average KPI by week:
daily_activity_summary_all_KPI %>%
However the result is the following:
15 5.29
16 5.29
17 5.29
18 5.29
19 5.29
Any idea what am I missing?

in general the advice is do not use $ to identify vectors within frames, where you have already declared said frame to be the source for any vectors to be used within the tidyverse function calls.
group_by already had daily_activity_summary_all_KPI passed in, therefore dont repeat daily_activity_summary_all_KPI just use the variable directly ActivityDate. same again for summarise, dont repeat the dataframe name that you already declared. Tidyverse syntax is meant to save you from this repetition that base R would require of you, and it is an effective way to break the code.

1 Like

I followed your suggestions and it worked! Many thanks!

The problem is that you grouped the data then referenced the original ungrouped data, so you got ungrouped results.

1 Like

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.