Skip to content
Prev 363180 / 398502 Next

adding a date column with dplyr

What's wrong with this?

df$Night <- as.POSIXct( paste(format(df$Date,'%Y-%m-%d'),'21:30'))
  or
df$Night <- trunc(df$Date,'day') + 21*60*60 + 30*60

I believe both of those satisfy "the day of tracking for each animal, but
with the time of 21:30". But perhaps you meant the day that tracking
started, when tracking lasted more than one day...


And then just add 24 hours ("one day later") to that one special case

df$Night[df$ID=='M16c'] <- df$Night[df$ID=='M16c'] + 24*60*60

-Don