[R] class of strptime() output

Jinsong Zhao jszhao at yeah.net
Tue Jan 6 06:17:45 CET 2015


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



More information about the R-help mailing list