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))
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.
Thank you
Harold
[[alternative HTML version deleted]]
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.
You seem to be trying to make POSIXt into something it isn't, as though this
was Excel.
First, POSIXt is not the same as numeric. You can convert between them, but they
are not the same. If you want to do numeric operations, convert.
Second, POSIXt is not time of day only. When you provide only minutes and
seconds to strptime, it includes the current date in the result as well. Thus,
values converted today will be different than values converted tomorrow. You
should probably pick a specific date to include in every "time" value,
and paste it with the actual data before converting.
Finally, formatting of all non-character data is always associated with
conversion to character. You either need to reconvert on demand or keep a copy
of the data around unconverted for use when you need it.
Oh, and your use of HTML is leading to corruption of your code. Learn to use
your email program so you don't send us garbage to guess at.
---------------------------------------------------------------------------
Jeff Newmiller The ..... ..... Go Live...
DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live
Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.
On March 30, 2015 6:15:09 PM PDT, "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))
>
>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.
>
>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.
On Tue, Mar 31, 2015 at 01:15:09AM +0000, Doran, Harold 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))I suspect you will find that manipulating times as numeric quantities (so you can do arithmetic on them) will be easier if you convert to seconds (possibly using a different vector, leaving "times" as it was).> 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.So do that with a copy -- the output of format() need not destroy its input.>...Peace, david -- David H. Wolfskill r at catwhisker.org Those who murder in the name of God or prophet are blasphemous cowards. See http://www.catwhisker.org/~david/publickey.gpg for my public key. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 949 bytes Desc: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20150330/3851a8ba/attachment.bin>