Evan の Logbook
✨ Updates
🎨 Style Guide
🧠 Creative Resources
🗒️ Mind Notes
🧭 Knowbase
📘 SOPs
🩺 Medical Research
🛠️ Tech Chronicles
💰 Fortune Blueprint
📈 R Visionary
📊 Statistics
🖼️ BioVis
📦为什么使用 lubridate?
type
Post
status
Published
date
Aug 12, 2025
slug
r-lubridate-intro
summary
介绍 lubridate 包的核心功能,包括日期时间解析、组件提取、加减运算、日期对齐与时间差计算,适合 tidyverse 工作流下的时间数据处理。
tags
lubridate
R
datetime
category
📈 R Visionary
icon
password
comment
Show
lubridate 是 tidyverse 中专门处理日期与时间的包,提供了比 base R 更直觉、简洁、强大的 API。在时间数据处理中,它能大幅减少代码量并提高可读性,非常适合与
dplyr、ggplot2 等配合使用。💡 适用场景
- ⏳ 快速解析日期时间(如
ymd("2023-10-05"))
- 🧩 提取时间组件(年、月、日、小时等)
- 🔁 时间运算(加减天数、月份、小时等)
- 🧹 日期对齐(按月、周、季度聚合)
- 📊 时间序列可视化与分析(配合 ggplot2、dplyr)
🧠 自动识别日期格式
优势:免去手动指定 %Y-%m-%d 这种复杂格式,解析更直观。
🕒 获取当前时间
📤 提取时间组件
小贴士:在 ggplot2 绘图前,可以用这些函数快速生成分组变量。
🔁 时间加减运算
优势:支持 days()、months()、years() 等直观的加减。
📏 日期对齐(聚合前常用)
常用于按月、按周进行分组统计。
⏱ 计算时间差
选择建议:interval() 更适合做区间运算,difftime() 则适合直接获取差值。
Prev
make_date() & make_datetime():从字段构造时间对象
Next
ISO 8601 国际时间标准
Loading...
YouTube 使用笔记