0

I would like to summarise hourly weather data by day (get the total precipitation and maximum wind speed daily). Found a code snippet on the web, but it results in only one observation for both variables, instead of daily observations.

How can I change this particular code? And what are the other ways exist to perform this task?

Thanks!

library(nycflights13)
library(dplyr)

precip <- weather %>%
  group_by(month, day) %>%
  filter(month < 13) %>%
 summarise(totprecip = sum(precip), maxwind = max(wind_speed))
Feodo
  • 3
  • 3
  • 1
    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/how-to-make-a-great-r-reproducible-example/5963610). This will make it much easier for others to help you. – Jaap Feb 28 '16 at 14:08
  • 1
    I don't understand the problem, when I run your code I get a dataframe with columns month, day, total precip and max wind. – Heroka Feb 28 '16 at 14:18
  • If you want the variables added to the long format, you should use mutate (and not usmmarise) – Heroka Feb 28 '16 at 14:27
  • Can you please elaborate on _what exactly_ it is you want to do? Summarize just does that: it gets you one value for each combination of values in `group_by`. What's the larger problem you're trying to solve? – Heroka Feb 28 '16 at 18:13
  • @Heroka Thanks for commenting promptly. I still get the same result, when using group_by and summarise consecutively,with another data set, too (hflights). As if it did not recognize the group_by funciton and takes only the sum and maximum of all data, instead of daily. I tried mutate, but could not get the syntax right. Could you please maybe post this version with mutate? – Feodo Feb 28 '16 at 18:14
  • I'm trying to add average daily departure delays to flight dataset. Also, add max wind and average precipitation daily (which are per hour by default) to weather dataset. Then merge the two dataset together. – Feodo Feb 28 '16 at 18:23
  • And you don't get expected output by replacing 'summarise' with 'mutate' in this code? I did, when I do that (columns are just not visible) – Heroka Feb 28 '16 at 18:59
  • Possibly I had messed something else up at previous tentatives, now I do get the result,thanks heaps – Feodo Feb 28 '16 at 19:55

0 Answers0