我有一個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,...): 字符串不一個標準的明確格式' 你知道發生了什麼? –