←
PDF 337 / 520 Tibbles
→
English · PDF 337
Original PDF page 337
中文 · PDF 337

typeof(x) #> [1] "double" attributes(x) #> $tzone #> [1] "UTC" #> #> $class #> [1] "POSIXct" "POSIXt"

tzone 属性是可选的。它控制时间的打印方式,而不是它所指的绝对时间:

attr(x, "tzone") <- "US/Pacific" x #> [1] "1969-12-31 17:00:00 PST" attr(x, "tzone") <- "US/Eastern" x #> [1] "1969-12-31 20:00:00 EST"

还有一种日期时间类型叫做 POSIXlt。它们构建在命名列表之上:

y <- as.POSIXlt(x) typeof(y) #> [1] "list" attributes(y) #> $names #> [1] "sec" "min" "hour" "mday" "mon" "year" #> [7] "wday" "yday" "isdst" "zone" "gmtoff" #> #> $class #> [1] "POSIXlt" "POSIXt" #> #> $tzone #> [1] "US/Eastern" "EST" "EDT"

POSIXlt 在 tidyverse 中很少见。它们确实会出现在基础 R 中,因为提取日期的特定组成部分(如年份或月份)时需要用到它们。由于 lubridate 提供了辅助函数让你来完成这些操作,所以你不需要它们。POSIXct 总是更易于使用,因此如果你发现自己有一个 POSIXlt,应该始终使用 lubridate::as_date_time() 将其转换为常规的日期时间。

Tibble

Tibble 是增强的列表。它们有三个类:tbl_df、tbl 和 data.frame。它们有两个属性:(列)名称和 row.names。