2

I am trying to create a new table from an existing one.

I've selected the columns I need, Month, Year, and Temperature. There are is one row for each day.

I've managed to add another column, with a 1 or 0 for each day above freezing.

I would now like to aggregate the rows so I have a row for each season and a column for each year, as well as an annual total row.

KAN_U <- kan_u_df %>% 
  select(Year, MonthOfYear, AirTemperature.C.)  
  KAN_U$Melt <- as.numeric(KAN_U$AirTemperature.C. > 0)

head(KAN_U)

    Year MonthOfYear AirTemperature.C.         Melt
1   2009    4       -999.00              0
2   2009    4       -25.30               0
3   2009    4       -23.44               0
4   2009    4       -28.18               0
5   2009    4       -32.15               0
6   2009    4       -24.35               0'

I would like my final table to look as such

     Total    Winter    Spring    Summer    Autumn 
2009   10       0          2         7        1 
2010   10       0          2         7        1 
2011   10       0          2         7        1 
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
S.OBrien
  • 21
  • 1
  • As there isn't a reproducible example provided.. you can use `dplyr`, `df %>% mutate(Check_freeze = ifelse(Temp < 0, "1", "0")) ` to give you the new column with 1/0 for temp below or above 0 celcius. – Javier Jan 29 '19 at 01:22
  • Please edit your question as to include some data (using `dput()`) to make it reproducible. – erc Jan 29 '19 at 07:50

0 Answers0