I have a data frame as follows
S = c("28/05/2016 07:00", "29/05/2016 07:00", "30/05/2016 07:00")
S1 = c("2016-05-28", "2016-05-29", "2016-05-30")
df = data.frame(S, S1)
I want to convert the dates to day of the year. Using
df$Day_S <- yday(df$S)
df$Day_S1 <- yday(df$S1)
gives
S S1 Day_S Day_S1
1 28/05/2016 07:00 2016-05-28 141 149
2 29/05/2016 07:00 2016-05-29 140 150
3 30/05/2016 07:00 2016-05-30 140 151
which works only for the format of the 'S1' dates.
Ive tried
df$S_1 <- format(as.POSIXct(df$S,format='%d/%m/%Y'),format='%d/%m/%Y')
df$Day_S_1 <- yday(df$S_1)
but this still gives the wrong day of the year.
How can i convert the 'S' column to day of the year?