[R] as.POSIXct on vector weird output

jim holtman jholtman at gmail.com
Tue Sep 13 05:06:01 CEST 2011


'f$V1' is a factor.

try

as.POSIXct(as.character(f$V1), format="%m/%d/%Y %H:%M:%S")

You need to convert to a character first.

On Mon, Sep 12, 2011 at 7:24 PM, bradford <fingermark at gmail.com> wrote:
> I don't know R, so maybe I've done something wrong, but I'm working off an
> example I saw on the web and wondering why as.POXIXct isn't returning the
> same result on f$V1 as it is on z.  Did I do something wrong?  Or is it a
> problem with my build?
>
>> f$V1
>  [1] 09/11/2011 13:46:39 09/11/2011 13:45:18 09/11/2011 13:44:58
>  [4] 09/11/2011 13:40:02 09/11/2011 13:37:58 09/11/2011 13:36:09
>  [7] 09/11/2011 13:32:31 09/11/2011 13:25:29 09/11/2011 13:24:40
> [10] 09/11/2011 13:23:48
> 10 Levels: 09/11/2011 13:23:48 09/11/2011 13:24:40 ... 09/11/2011 13:46:39
>> z
> [1] "09/11/2011 13:46:39"
>> as.POSIXct(z, format="%m/%d/%Y %H:%M:%S")
> [1] "2011-09-11 13:46:39 EDT"
>> as.POSIXct(f$V1, format="%m/%d/%Y %H:%M:%S")
>  [1] "0009-11-20 EST" "0009-11-20 EST" "0009-11-20 EST" "0009-11-20 EST"
>  [5] "0009-11-20 EST" "0009-11-20 EST" "0009-11-20 EST" "0009-11-20 EST"
>  [9] "0009-11-20 EST" "0009-11-20 EST"
>
> ---------
> R version 2.12.2 (2011-02-25)
> Copyright (C) 2011 The R Foundation for Statistical Computing
> ISBN 3-900051-07-0
> Platform: x86_64-apple-darwin10.8.0 (64-bit)
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> 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.
>



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?



More information about the R-help mailing list