On Fri, 15 Jan 2021 at 18:55, Jibrin Alhassan <jibrin.alhas...@unn.edu.ng>
wrote:
>
> 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")

Look at the package lubridate.
Here is an example for you:

library(lubridate)

v <- seq(ymd("2020-01-01"),ymd("2022-01-01"),1)
df <- data.frame(date = v, day = day(v), month = month(v),year = year(v))
str(df)
head(df,3)
tail(df,3)

'data.frame': 732 obs. of  4 variables:
 $ date : Date, format: "2020-01-01" "2020-01-02" ...
 $ day  : int  1 2 3 4 5 6 7 8 9 10 ...
 $ month: num  1 1 1 1 1 1 1 1 1 1 ...
 $ year : num  2020 2020 2020 2020 2020 2020 2020 2020 2020 2020 ...
        date day month year
1 2020-01-01   1     1 2020
2 2020-01-02   2     1 2020
3 2020-01-03   3     1 2020
          date day month year
730 2021-12-30  30    12 2021
731 2021-12-31  31    12 2021
732 2022-01-01   1     1 2022

Regards
Martin

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to