I am attempting to take a column of the format POSIXct (or, if necessary, chr) and generate a new column that represents the day of year for that date (some number from 1-366, depending on the year). For example, say I have a row with value "2020-11-16" in the format POSIXct, how can I extract the day of year (day 321 in this case) and do so over the course of an entire column?
Asked
Active
Viewed 384 times
1 Answers
2
Hi you can use the lubridate- Package
> library(lubridate)
> yday(as.POSIXct("2020-11-16"))
[1] 321
of course this also works with a vector/ column:
v<-paste0("2020-11-",1:30)
yday(as.POSIXct(v))

user12256545
- 2,755
- 4
- 14
- 28