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

后端 未结 3 1651
慢半拍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

    dplyr is a great tool, but in this case I'm not sure it's the best for the job. This accomplishes your task:

    span$CHECK <- ave(dst(span$date), as.Date(span$date, tz = tz(span$date)), FUN = any)
    

    I think ave is a terrible name for this function, but if you can remember it exists, it's often quite useful when you want to join a summary back to the data.frame it came from.

提交回复
热议问题