2014-03-04 101 views
0

我有一年的小時天氣數據。我喜歡從中提取每日最大值,平均值等。所以我在這裏尋找幫助。我碰到以下主題:將小時數據轉換爲每日最大值,最小值,平均值

convert hourly rainfall data into daily in specific time interval

我能不能理解波普答案。由於我不到50分,我無法在那裏添加評論。所以我發佈這個問題。 任何人都可以解釋這些命令嗎?

fun <- function(s,i,j) { sum(s[i:(i+j-1)]) } 
sapply(X=seq(1,24*nb_of_days,24),FUN=fun,s=your_time_serie,j=24) 
+0

你可以發表你的數據'head'? – Nishanth

+2

如果您提供[**最小,可重現的示例**],它將更容易幫助(http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610) – Henrik

+0

請考慮我提到的數據.........請好好解釋一下那個降雨量數據的函數 – Barun

回答

1

建議你用dplyr包聚合 - 見下:

rain<-read.table(sep="|",text="1970-01-05 00:00:00|1.0 
1970-01-05 01:00:00|1.0 
1970-01-05 02:00:00|1.0 
1970-01-05 03:00:00|1.0 
1970-01-05 04:00:00|1.0 
1970-01-05 05:00:00|3.6 
1970-01-05 06:00:00|3.6 
1970-01-05 07:00:00|2.2 
1970-01-05 08:00:00|2.2 
1970-01-05 09:00:00|2.2 
1970-01-05 10:00:00|2.2 
1970-01-05 11:00:00|2.2 
1970-01-05 12:00:00|2.2 
1970-01-05 13:00:00|2.2 
1970-01-05 14:00:00|2.2 
1970-01-05 15:00:00|2.2 
1970-01-05 16:00:00|0.0 
1970-01-05 17:00:00|0.0 
1970-01-05 18:00:00|0.0 
1970-01-05 19:00:00|0.0 
1970-01-05 20:00:00|0.0 
1970-01-05 21:00:00|0.0 
1970-01-05 22:00:00|0.0 
1970-01-05 23:00:00|0.0 
1970-01-06 00:00:00|0.0") 

require(dplyr) # for aggregation 

group_by(rain,day=as.Date(rain$V1)) %.% 
    summarise(total=sum(V2)) 

     day total 
1 1970-01-05 32 
2 1970-01-06  0 
相關問題