Friday 24 July 2015

R: POSIXct , POSIXlt Working with times

POSIXct & POSIXlt classes represent times. Dates are stored internally as number of seconds since 1970-01-01.

POSIXct stores seconds in very large integer since UNIX epoch (+some other data), and POSIXlt stores a list of day, month, year, hour, minute, second, etc. By using POSIXlt you can extract seconds, minutes, hour, day, month etc.,

as.POSIXlt converts a variety of data types to POSIXlt, and as.POSIXct converts a variety of data types to POSIXct
> p<-as.POSIXct("1988-06-06")
> names(unclass(p))
NULL
> p
[1] "1988-06-06 IST"
> 
> 
> 
> p<-as.POSIXlt("1988-06-06")
> names(unclass(p))
 [1] "sec"    "min"    "hour"   "mday"   "mon"    "year"   "wday"   "yday"   "isdst"  "zone"   "gmtoff"
> 
> p$sec
[1] 0
> 
> p$min
[1] 0
> 
> p$hour
[1] 0
> 
> p$mday
[1] 6
> 
> p$mon
[1] 5
> 
> p$year
[1] 88
> 
> p$wday
[1] 1
> 
> p$yday
[1] 157
> 
> p$isdst
[1] 0
> 
> p$zone
[1] "IST"




Prevoius                                                 Next                                                 Home

No comments:

Post a Comment