Data and Times

来源:互联网 发布:卖跑步装备的淘宝店 编辑:程序博客网 时间:2024/06/01 13:54

Data and Time

> d1 <- Sys.Date() > class(d1)[1] "Date"> unclass(d1)[1] 16978> d2 <- as.Date("1969-01-01")> unclass(d2)[1] -365

| As you may have anticipated, you get a negative number. In this case, it’s -365, since 1969-01-01 is exactly one calendar

| year (i.e. 365 days) BEFORE 1970-01-01.

> t1 <- Sys.time()> t1[1] "2016-06-26 15:28:49 CST"> class(t1)[1] "POSIXct" "POSIXt" > class(t1)[1] "POSIXct" "POSIXt" > t2[1] "2016-06-26 15:30:09 CST"> class(t2)[1] "POSIXlt" "POSIXt"  > t2[1] "2016-06-26 15:30:09 CST"> unclass(t2)$sec[1] 9.688538$min[1] 30$hour[1] 15$mday[1] 26$mon[1] 5$year[1] 116$wday[1] 0$yday[1] 177$isdst[1] 0$zone[1] "CST"$gmtoff[1] 28800attr(,"tzone")[1] ""    "CST" "CDT"> str(unclass(t2))List of 11 $ sec   : num 9.69 $ min   : int 30 $ hour  : int 15 $ mday  : int 26 $ mon   : int 5 $ year  : int 116 $ wday  : int 0 $ yday  : int 177 $ isdst : int 0 $ zone  : chr "CST" $ gmtoff: int 28800 - attr(*, "tzone")= chr [1:3] "" "CST" "CDT"

| Now that we have explored all three types of date and
time objects, let’s look at a few functions that extract useful

| information from any of these objects – weekdays(),
months(), and quarters().

| The same line of thinking applies to addition and the other comparison operators. If you want more control over the units

| when finding the above difference in times, you can use difftime(), which allows you to specify a ‘units’ parameter.

| Use difftime(Sys.time(), t1, units = ‘days’) to find the amount of time in DAYS that has passed since you created t1.

0 0