[R] Help with POSIX

Ben Tupper ben.bighair at gmail.com
Tue Mar 31 03:37:40 CEST 2015


Hi,


On Mar 30, 2015, at 9:15 PM, Doran, Harold <HDoran at air.org> wrote:

> I�m struggling a bit with learning about POSIX objects to do some basic things with objects of this class. Suppose I have the following simple example
> 
> times <- c("03:20", "29:56", "03:30", "21:03", "56:26")
> 
> aa <- strptime(times, "%M:%S�)
> 
> I can do means, and some other basic things, but I cannot correlate the objects with some other variable
> 
> cor(aa, rnorm(5))
> 


You can cast your POSIXlt values to numeric

cor(as.numeric(aa), rnorm(5))


> Also, for purposes of a user-interface I have built with shiny, I need for the time to be viewed as simply as minutes:seconds, such as this
> 
> format(aa, '%M:%S�)
> 
> But of course after doing this I lose the ability to work with this object as a time variable.
> 

You may need to keep a copy of your times in a POSIX or numeric format in addition to converting to character.  It's hard to tell without more information.

Cheers,
Ben

> Thank you
> Harold
> 
> 	[[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.



More information about the R-help mailing list