[R] Mean of dates

Jue Lin-Ye jl.iccp at gmail.com
Fri Apr 24 13:47:30 CEST 2015


On 24 April 2015 at 12:59, Achim Zeileis <Achim.Zeileis at uibk.ac.at> wrote:

>
>
> On Fri, 24 Apr 2015, Jue Lin-Ye wrote:
>
>  Dear fellow R-help members,
>>
>> If my data is
>>
>> YYYY MM DD HH
>> 2015 04 24 01
>> 2015 04 24 02
>> 2015 04 24 06
>>
>> Where
>>
>> YYYY: year
>> MM:month
>> DD:day
>> HH: hour
>>
>> How could I calculate the mean of the ISOdatetime(YYYY,MM,DD,HH,0,0) of
>> these?
>>
>
> With the mean() method? On my machine:
>
> R> mean(ISOdatetime(YYYY,MM,DD,HH,0,0))
> [1] "2015-04-24 03:00:00 CEST"
>
>
​Hi! Maybe the problem is when I try to create the vector that I am looking
for. Please ​check this code out.


​X_season1<-matrix(c(2015, 04, 24, 01, 2015 ,04, 24, 02,
  2015 ,04 ,24 ,03 ,2015 ,04 ,24 ,05,
  2015, 04, 24 ,06 ,2015, 04 ,24
,10),3,8,byrow=T);colnames(X_season1)<-c("AAi","MMi","DDi","HHi","AAf","MMf","DDf","HHf")
time2<-NULL
for(i5 in 1:nrow(X_season1)){
  time2[i5]<-mean(

as.Date(c(ISOdatetime(X_season1[i5,"AAi"],X_season1[i5,"MMi"],X_season1[i5,"DDi"],X_season1[i5,"HHi"],0,0),

ISOdatetime(X_season1[i5,"AAf"],X_season1[i5,"MMf"],X_season1[i5,"DDf"],X_season1[i5,"HHf"],0,0)),
                          format="%YYYY-%mm-%dd %H:%m:%s"),trim=0)}​

​Thanks!​



> hth,
> Z
>
>  Note: I set minutes and seconds to 0, as I don't have data for them.
>>
>> ?Thank you in advance!?
>>
>> --
>> Jue Lin-Ye
>>
>> ---------------------------------------------------------------
>> Civil Engineering phD candidate
>> Maritime Engineering Laboratory (LIM)
>> Universitat Politècnica de Catalunya (UPC)
>> C/Jordi Girona 1-3, Barcelona 08034 (Spain)
>> -----------------------------------------------------------------
>>
>>         [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
>


-- 
Jue Lin-Ye

---------------------------------------------------------------
Civil Engineering phD candidate
Maritime Engineering Laboratory (LIM)
Universitat Politècnica de Catalunya (UPC)
C/Jordi Girona 1-3, Barcelona 08034 (Spain)
-----------------------------------------------------------------

	[[alternative HTML version deleted]]



More information about the R-help mailing list