0

I'm a beginner stuck in R trying to aggregate daily weather data to weekly. My data looks as follows:

STN YYYYMMDD    DDVEC   FHVEC   FG  FHX FHN FXX FXXH    TG  TN  TX  T10N Weeknr
235 20161231    227     70      70  80  60  120 10      80  71  87  69   52 
235 20161230    227     53      55  60  30  90  6       52  -10 73  -9   52

The idea is to take the average of every day of the week, for every variable except for the first column (indicating locating of measurement), and aggregate it to weekly. I've managed to create a column including the week number, without the year however (as can be seen in the data above).

I've just realised it's different from the alleged duplicate in the following way. The variable STN indicates the weather station, which the results should also be grouped by. So, it should be grouped weekly per station (there's a total of 30 stations with an equal number of observations). I hope someone has the answer!

  • Please share a reproducible example of your dataset, not screenshot. – www May 08 '18 at 08:35
  • 1
    Please post the output of `dput(Data)` instead, where Data is your data frame. – hpesoj626 May 08 '18 at 08:36
  • 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. – Sotos May 08 '18 at 08:46
  • Convert 2nd column to date, [extract week](https://stackoverflow.com/questions/22439540/how-to-get-week-numbers-from-dates), group by week column, and get mean on all columns. See https://stackoverflow.com/questions/21644848/summarizing-multiple-columns-with-dplyr – zx8754 May 08 '18 at 08:47
  • Thanks, but I can't get the dplyr to work on my dataset. How do I tell the function that is should group by date, making a week of every 7 days? – Luuk Appels May 08 '18 at 09:20
  • I updated my question – Luuk Appels May 08 '18 at 11:51
  • What is your definition of "week", please?. There are many possibilities as discussed [here](https://stackoverflow.com/a/45587644/3817004), e.g. – Uwe May 16 '18 at 08:00

0 Answers0