[R] class of strptime() output

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Tue Jan 6 07:00:22 CET 2015


Because data.frame converts it. I don't know what rationale was originally used to justify including that transformation automatically, but I think it is much better this way than having POSIXlt in the data frame. POSIXlt is itself like a little data frame, and having data frames inside of data frames gets confusing. I wish column assignment also did this transformation...

b$date2 <- a # leads to overcomplicated data frame
b$date3 <- as.POSIXct(a) # my usual idiom
---------------------------------------------------------------------------
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 January 5, 2015 9:17:45 PM PST, Jinsong Zhao <jszhao at yeah.net> wrote:
>On 2015/1/5 20:51, David Winsemius wrote:
>>
>> On Jan 5, 2015, at 5:47 PM, Jinsong Zhao wrote:
>>
>>> On 2015/1/5 17:28, Ben Bolker wrote:
>>>> Jinsong Zhao <jszhao <at> yeah.net> writes:
>>>>
>>>>
>>>>> In the following code snippet,
>>>>> #
>>>>> a <- strptime("121114 0510", "%m%d%y %H%M")
>>>>> b <- data.frame(date = a, res = 1:5)
>>>>> class(a)
>>>>> class(b[1,1])
>>>>> #
>>>>> I am wondering why the class of a and b[1,1] are not the same.
>>>>>
>>>>> How to make the class of a and b[1,1] to be same?
>>>>
>>>>    How about
>>>>
>>>>    a <- as.POSIXct(strptime(...))
>>>>
>>>> ?  (See ?POSIXct)
>>>
>>> Thanks a lot.
>>>
>>> I have used as.POSIXct(...).
>>
>> You may have "used" it, but you don't show any code. I can think of
>several ways you could have _thought_ you "used it" but failed to make
>any changes to the underlying objects.  For instance you could have
>executed this code:
>>
>> as.POSIXct(a)
>>
>> Which would produce console output but have no effect on 'a'.
>>
>>
>>> I am wondering why the class of a and b[1,1] are not the same.
>>
>> We are wondering as well. What did you do?
>>
>>
>
>I am very sorry for the misleading of my reply.
>
>I wanted to say that I have used the as.POSIXct(...) in my code, and it
>
>give the same output for class(a) and class(b[1,1]), as in the
>following 
>code:
>
>a <- as.POSIXct(strptime("121114 0510", "%m%d%y %H%M"))
>aa <- strptime("121114 0510", "%m%d%y %H%M")
>b <- data.frame(date = aa, res = 1:5)
>
>What I am wondering is why class(aa) is different with class(b[1,1]).
>
>Best,
>Jinsong
>
>______________________________________________
>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