不规则时间序列的年、月或日平均值 [英] Annual, monthly or daily mean for irregular time series

查看:23
本文介绍了不规则时间序列的年、月或日平均值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是R"的新用户,我找不到好的解决方案.我得到了以下格式的时间序列:

I am a new user of "R", and I couldn't find a good solution to solve it. I got a timeseries in the following format:

>dates  temperature depth   salinity
>12/03/2012 11:26   9.7533  0.48073 37.607
>12/03/2012 11:56   9.6673  0.33281 37.662
>12/03/2012 12:26   9.6673  0.33281 37.672

我有一个不规则的可变测量频率,根据时间段每 15 分钟或每 30 分钟进行一次.我想计算每个变量的年、月和日平均值,无论一天/月/年的数据数量是多少.我阅读了很多关于包 zoo、timeseries、xts 等的内容,但我无法清楚地了解我需要什么(可能是因为我对 R 不够熟练......).

I have an irregular frequency for variable measurements, done every 15 or every 30 minutes depending on the period. I would like to calculate annual, monthly and daily averages for each of my variables, whatever the number of data in a day/month/year is. I read a lot of things about the packages zoo, timeseries, xts, etc. but I can't get a clear vision of what I nead (maybe cause I'm not skilled enough with R...).

我希望我的帖子是清楚的,如果不是,请不要犹豫告诉我.

I hope my post is clear, don't hesitate to tell me if it's not.

推荐答案

将您的数据转换为 xts 对象,然后使用 apply.daily 等来计算您想要的任何值.

Convert your data to an xts object, then use apply.daily et al to calculate whatever values you want.

library(xts)
d <- structure(list(dates = c("12/03/2012 11:26", "12/03/2012 11:56", 
"12/03/2012 12:26"), temperature = c(9.7533, 9.6673, 9.6673), 
    depth = c(0.48073, 0.33281, 0.33281), salinity = c(37.607, 
    37.662, 37.672)), .Names = c("dates", "temperature", "depth", 
"salinity"), row.names = c(NA, -3L), class = "data.frame")
x <- xts(d[,-1], as.POSIXct(d[,1], format="%m/%d/%Y %H:%M"))
apply.daily(x, colMeans)
#                     temperature     depth salinity
# 2012-12-03 12:26:00    9.695967 0.3821167   37.647

这篇关于不规则时间序列的年、月或日平均值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆