我有一个excel文件(.xlsx),它包含三列,标题为:'datetime'(例如:2008年10月1日10时10分,10/1/2008 0: 20等),'RH'(例如:0.46)和'wind_mps'(例如:3.71)。我希望将10分钟间隔数据转换为RH和wind_mps列的小时平均数据。将10分钟的间隔数据转换为小时平均值
我无法将Excel数据插入到此问题中。对于那个很抱歉。如果有人告诉我如何处理,我可以编辑我的问题。
类似的问题已在how to convert by the minute data to hourly average data in R得到解答,但我是R新手,无法对我的数据使用相同的技术。我也尝试使用'zoo','chron'和'xts'软件包来执行此操作,如http://rpubs.com/hrbrmstr/time-series-machinations,但它们似乎在R 3.02中不起作用。
我试图在Excel中做到这一点,但无法找到一个相当简单的技术。
我能够实现将每小时数据转换为使用Excel宏的另一个数据集的日常平均值的类似任务,但我无法为10分钟的数据做到这一点。宏如下:
Global year As Integer
Sub Calculate()
Dim start_year As Integer
Dim end_year As Integer
Dim cell_count As Integer
start_year = Cells(19, "M").Value
end_year = Cells(48, "M").Value
year = start_year
cell_count = 19
Do While year < (end_year + 1)
Dim row As Integer
Dim sum As Double
Dim count As Integer
Dim init_row As Integer
init_row = 6
sum = 0
count = 0
Dim cv As Integer
cv = 3
Do Until cv = year
cv = Cells(init_row, "C").Value
init_row = init_row + 1
Loop
row = init_row - 1
Worksheets("Sheet1").Activate
Dim cv1 As Integer
cv1 = Cells(row, "C").Value
Do While cv1 = year
sum = sum + Cells(row, "F").Value
count = count + 1
row = row + 1
cv1 = Cells(row, "C").Value
Loop
Cells(cell_count, "N").Value = sum
Cells(cell_count, "O").Value = count
Cells(cell_count, "P").Value = sum/count
cell_count = cell_count + 1
year = year + 1
Loop
End Sub
对于我来说,使用R,Excel函数,宏或其他技术并不重要。如果有人能告诉我如何将这个大约50000的RH和wind_mps数据集转换为小时平均值,那将会很棒。
在此先感谢。
什么这是很容易与XTS /动物园,我向你保证,他们有R工作-3.0.2。 –
所以你想,每个值的小时平均值(换句话说,它会重复6次 - 每10分钟一次)? –
@JoshuaUlrich我试过xts/zoo。有没有办法将数据帧转换为xts支持的矩阵?我尝试这样做: matrix_rhwind <-as.xts(rh_wind2,DATEFORMAT = 'POSIXct') 却得到:“错误as.POSIXlt.character(X,TZ,...): 字符串不一个标准的明确格式' 你知道发生了什么? –