Using the result of summarise (dplyr) to mutate the original dataframe

后端 未结 3 1652
慢半拍i
慢半拍i 2020-12-18 12:12

I have a rather big dataframe with a column of POSIXct datetimes (~10yr of hourly data). I would flag all the rows in which the day falls in a Daylight saving period. For ex

3条回答
  •  一生所求
    2020-12-18 13:04

    The best solution to get the job done, as suggested by @aosmith, is.

    limits = span %>% group_by(YEAR) %>% mutate(minDOY=min(DOY[DLS]),maxDOY=max(DOY[DLS]),CHECK=FALSE)
    
    limits$CHECK[(limits2$DOY >= limits$minDOY) & (limits$DOY <= limits$maxDOY) ] = TRUE
    

    The use of the ave function is a good choice, but I personally prefer to stick to the 'dplyr' package.

提交回复
热议问题