[R] median for time data

Jannis v. Buttlar jannis.buttlar at gmx.de
Tue Dec 1 19:52:26 CET 2009



uvilla schrieb:
> When I use strptime() I just get NA NA NA
> I`m new at using R, must finisth this work thoug
> 
> I guess Im doing totally wrong, actually everytime i try to use "POSIXct" it
> doesn`t work
> 

If you have a look at help(strptime) you find that you have to specify 
the format in which you time is written.

Try

strptime("08:10:10","%H:%M:%S")

The stuff after the comma in the "" is the way to give strptime the format.

Now you only have use

strptime(vectorwithyourtime,"%H:%M:%S")

and you should get a vector with R format times out of it. It uses 
todays date though but for your calculations this should work. This 
POSIXct format is not very handy to use though, so you perhaps better 
consider using library(chron) as Gabor suggested.




> Thanks a lot
> 
> 
> 
> Jannis wrote:
>> Hi,
>>
>>
>> try to convert this to the R time format "POSIXct" or "POSIXlt" via 
>> strptime(). Then you can simply substract them. I am not sure whether a 
>> median can be calculated though (should be possible as POSIXct stores 
>> the value as seconds since 1970....)
>>
>> Best
>> Jannis
>>
>> uvilla schrieb:
>>> Hi everybody
>>>
>>> How do I do to calculate the median and average of a colum of time data
>>> like
>>> this: "8:50:10". I also need to plot the time difference between two
>>> colums
>>> Thanks a lot
>> ______________________________________________
>> R-help at r-project.org mailing list
>> 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.
>>
>>
>




More information about the R-help mailing list