r - 从 excel 导入日期以随时间推移作为样本绘制
问题描述
我正在导入一个样本列表(带有日期),并希望将它们绘制为随时间变化的采样频率
从 .csv 导入的数据(事件日期 = d/m/Y)为“col_character()”
我是一个完全的新手 - 我从哪里开始?
解决方案
这是将字符类日期转换为可绘图格式的示例数据。
set.seed(4) # to ensure replicability
dat <- data.frame(date=sprintf("%02d/01/2019", 1:31), value = sample(1:10, 31, replace=TRUE), stringsAsFactors = FALSE)
str(dat)
# 'data.frame': 31 obs. of 2 variables:
# $ date : chr "01/01/2019" "02/01/2019" "03/01/2019" "04/01/2019" ...
# $ value: int 1 6 2 4 7 8 6 3 1 1 ...
dat$date <- as.Date(dat$date, format="%d/%m/%Y") #transfor the character format into date format
str(dat)
# 'data.frame': 31 obs. of 2 variables:
# $ date : Date, format: "2019-01-01" "2019-01-02" "2019-01-03" "2019-01-04" ...
# $ value: int 1 6 2 4 7 8 6 3 1 1 ...
with(dat, plot(date, value, type="l")) #simple line plot
推荐阅读
- excel - VBscript - 如果值来自变量,Excel 无法找到
- javascript - onhashchange 无法完全监控哈希变化事件
- javascript - 无法在路线之间导航。VueJS
- spring-boot - WebFlux 新手的烦恼
- go - 用于动态枚举访问的 Protobuffer API
- google-calendar-api - 使用 API 修改 Google 日历重复事件
- go - 为什么我会通过渠道接收其他元素?
- java - 带有 HTML 的 Spring Boot
- asp.net - 为什么role.Name可以获取数据?
- node.js - 错误:ENOENT:没有这样的文件或目录,打开 './.babelrc'