[R] time

Don MacQueen macq at llnl.gov
Thu May 27 16:20:56 CEST 2004


Here is another way, not necessarily better.

Since you didn't provide any column names, let 
df$tm refer to the column of times, which I will 
assume is a vector of character strings.

## as a one-liner, results in a character object 
(the '2004-5-1' is arbitrary, use any valid date)
minute <- format(as.POSIXct(paste('2004-5-1',df$tm,sep='-')),'%M')

## in multiple lines, making it possible to plot 
the data with an axis having an accurate time 
scale
tm <- as.POSIXct(paste('2004-5-1',df$tm,sep='-'))

## as above, minute is a character object
minute <- format(tm,'%M')

## or this way, minute is a POSIXt object, also 
suitable for use with a time-scaled plot
minute <- trunc(tm,'mins')

-Don

At 10:52 PM +0200 5/26/04, Wolski wrote:
>Hi!
>I would extract the minutes from the time using sub (see ?sub) or (?grep)
>than use them as factors (?as.factors)
>and finally
>?tapply
>
>eg.
>tt<-1:10
>  fac<-c(rep(0,4),rep(1,6)) # here put the minutes from the time
>fac
>  [1] 0 0 0 0 1 1 1 1 1 1
>fac<-as.factor(fac)
>fac
>  [1] 0 0 0 0 1 1 1 1 1 1
>Levels: 0 1
>
>tapply(t,fac,max)
>  0  1
>  4 10
>
>Sincerely Eryk.
>
>
>
>*********** REPLY SEPARATOR  ***********
>
>On 5/26/2004 at 3:00 PM solares at unsl.edu.ar wrote:
>
>>Hi, i need select data from data frame, for example:
>>x is a data frame with values in jump to 5 seconds
>>12:10:00 51 //one minute
>>12:10:05 63
>>12:10:10 75
>>12:10:15 88
>>..
>>12:10:59 45
>>12:11:00 46 //another minute
>>12:11:05 11
>>..
>>Have a command what to select the data minute to  minute, for example
>>in the example above i need the maximun values minute to  minute
>>1° minute-->88
>>2° minute--> 46
>>Thanks Ruben
>>
>>______________________________________________
>>R-help at stat.math.ethz.ch mailing list
>>https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
>
>
>Dipl. bio-chem. Eryk Witold Wolski    @    MPI-Moleculare Genetic  
>Ihnestrasse 63-73 14195 Berlin       'v'   
>tel: 0049-30-83875219               /   \   
>mail: wolski at molgen.mpg.de        ---W-W---- 
>http://www.molgen.mpg.de/~wolski
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


-- 
--------------------------------------
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA




More information about the R-help mailing list