繁体   English   中英

如何在R中创建时间序列?

[英]How can I create time series in R?

我想在R中创建时间序列,但我遇到了问题。 我有30.07的风速数据。 到02.09。 在每小时的决议。 在x轴上应该是日期和时间以及y轴风速。 我试过这个脚本,但不幸的是它没有用。 谁能帮帮我吗? 这是我的代码:

options(stringsAsFactors = FALSE)



 input1 <- "C:\\Users\\wind_speed.csv"

    wind_speed <- read.csv(input1, sep=";")

    dput(wind_speed)

    library(ggplot2)

    wind_speed$dateasdate <-gsub("\\.", "-", wind_speed$date)

    wind_speed$dateasdate <- dmy(wind_speed$dateasdate)

    wind_speed$date = as.Date(wind_speed$date, format = "%d.%m%.%y")

    time <- strptime(wind_speed$time, format = "%H:%M:%S")

    wind_speed$x <- paste(wind_speed$date,wind_speed$time)

    timee2<- strptime(wind_speed$x, format= "%d.%m.%y %H:%M")

    p <-ggplot(wind_speed, aes(x=x, y=speed)) + geom_point(stat="identity") + 
      geom_line(linetype="dashed") 

print(p)

[时间序列应该看起来像图像,但在x轴上有日期和时间] [2]

我的数据看起来像这样

这是我的数据样本:

head(wind_speed)
        date     time speed
1 27.07.2018 01:00:00   1.3
2 27.07.2018 02:00:00   0.8
3 27.07.2018 03:00:00   1.2
4 27.07.2018 04:00:00   0.6
5 27.07.2018 05:00:00   0.8
6 27.07.2018 06:00:00   1.8

采用 -

library(xts)
a <- xts(df$speed, order.by=as.POSIXct(paste(df$date,df$time), format="%d.%m.%Y %H:%M:%S"))
plot.xts(a)

在此输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM