【问题标题】:how to convert time series "POSIXct" into Date format in R如何在R中将时间序列“POSIXct”转换为日期格式
【发布时间】:2020-05-05 15:28:11
【问题描述】:

我在 excel 文件中有每月的时间序列数据。它是“POSIXct”“POSIXt”类。我想将此数据转换为日期格式 =“%Y/%m”。我想增加一个月,使起始值从 95 年 2 月开始

    Date max    min     mean     PPT             Q
Jan-95  280.7   275.2   276.3   54.97001368 77.22654839
Feb-95  285.5   284.7   290.55  85.56014243 65.10167857
Mar-95  291.3   296.3   307.95  21.73403927 62.66664516
Apr-95  295.4    305    321     46.40860902 80.3805
May-95  302.3   314.6   335.4   101.350745  123.6887742
Jun-95  306.6   321.3   345.45  51.36630928 491.1493667
Jul-95  309.9   327.5   354.75  29.5892797  905.7528065
Aug-95  309.5   327.2   354.3   56.71881787 726.2029355
Sep-95  305.5   318     340.5   55.58525046 321.7907333
Oct-95  298     305.3   321.45  24.09003613 171.9048065
Nov-95  293.1   292     301.5   31.49880152 114.4126667
Dec-95  282.9   280.5   284.25  59.8837784  88.75790323

dataset <- read_excel("Gilgit.xlsx")
colnames(pr1)<-c("Date", "Q", "SEAS_1d")
pr1$Date<-pr1$Date+1 

【问题讨论】:

    标签: lubridate zoo


    【解决方案1】:

    基本上,当我在 R 中打开我的数据时,我有月度数据。它采用以下格式。

    pr1 <- read_excel("Gilgit.xlsx", sheet = 1)
    colnames(pr1)<-c("Date", "Q", "SEAS_1d")
    pr1$Date<-pr1$Date+1 
    db1<-merge(db, pr1, by=c("Date"))
    

    添加日期后,它看起来像: enter image description here

    【讨论】:

      猜你喜欢
      • 2014-08-21
      • 1970-01-01
      • 2020-09-20
      • 1970-01-01
      • 1970-01-01
      • 2013-04-24
      • 2016-02-26
      • 2021-12-22
      • 1970-01-01
      相关资源
      最近更新 更多