Using ifelse with transform in ddply

后端 未结 2 471
既然无缘
既然无缘 2021-01-19 04:15

I am trying to use ddply with transform to populate a new variable (summary_Date) in a dataframe with variables ID and

2条回答
  •  花落未央
    2021-01-19 04:58

    One Step ddply solution (also posted as comment)

    ddply(test.df, .(ID, floor_date(Date, "month")), mutate, 
      length_x = length(ID), 
      summary_Date=as.POSIXct(ifelse(length_x < 5, round_date(Date, "month") ,Date)
        , origin="1970-01-01 00:00.00", tz="GMT")
    )
    

提交回复
热议问题