I have data with multiple observations per day, and I want to construct a table of daily averages. My instinctive approach (from other programming languages) is to sort the data by date and write a for loop to go through and average it out. But every time I see an R question involving for loops, there tends to be a strong response that R handles vector-type approaches much better. What would a smarter approach be to this problem?
For reference, my data looks something like
date       observation
2017-4-4   17
2017-4-4   412
2017-4-4   9
2017-4-3   96
2017-4-3   14
2017-4-2   8
And I would like the output to be a new data frame that looks like
date       average
2017-4-4   146
2017-4-3   55
2017-4-2   8
 
     
    