[R] Need help on "date"

jim holtman jholtman at gmail.com
Tue Sep 18 12:48:30 CEST 2007


Here is one way of doing it:

> x <- as.POSIXct("2005-09-01")
> x
[1] "2005-09-01 GMT"

> x.lt <- as.POSIXlt(x)
> x$mon+1
> x.lt$mon+1
[1] 9
> x.lt$year+1900
[1] 2005
> dput(x.lt)
structure(list(sec = 0, min = 0L, hour = 0L, mday = 1L, mon = 8L,
    year = 105L, wday = 4L, yday = 243L, isdst = 0L), .Names = c("sec",
"min", "hour", "mday", "mon", "year", "wday", "yday", "isdst"
), class = c("POSIXt", "POSIXlt"), tzone = "GMT")
> x.lt$mday
[1] 1
>


On 9/18/07, Arun Kumar Saha <arun.kumar.saha at gmail.com> wrote:
> Dear all,
>
> I have a variable 'x' like that:
>
> > x
> [1] "2005-09-01"
>
> Here, 2005 represents year, 09 month and 01 day.
>
> Now I want to create three variables naming: y, m, and d such that:
>
> y = 2005
> m = 09
> d = 01
>
> can anyone tell me how to do that?
>
> Regards,
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> 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.
>


-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?



More information about the R-help mailing list