[R] Converting "day of year" to "year", "month" and "day"
w||||@mwdun|@p @end|ng |rom gm@||@com
Fri Jan 15 20:20:16 CET 2021
Use one of the POSIXt classes, POSIXct or POSIXlt, instead of the Date
They have more methods for doing arithmetic. E.g.,
> dates <- as.POSIXct(tz="UTC", c("2004-03-01", "2005-03-01"))
> difftime(dates, trunc(dates, units="year"), units="days") # add 1 if you
want YYYY-01-01 to be day 1 instead of day 0
Time differences in days
 60 59
There are packages like 'zoo' that make many time/date operations simpler,
but the above
works with core R.
On Fri, Jan 15, 2021 at 9:55 AM Jibrin Alhassan <jibrin.alhassan using unn.edu.ng>
> Dear R users,
> I am very new to R software. I have solar wind speed data needed for my
> work. How do I convert day in the year to year, month, and day with R
> software? I have used this code
> as.Date(0, origin = "1998-01-01")
> but it can only convert one day of the year at a time. Meanwhile, I have up
> to the 1998-2002 data set. Attached is my data.
> Kindly help, please.
> Jibrin Alhassan
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]
More information about the R-help