[R] Converting from char to POSIX:

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Jul 28 18:16:44 CEST 2008


On Mon, 28 Jul 2008, Agustin Lobo wrote:

> Given char vector delme2:
>> str(delme2)
> chr [1:1065] "30-1-08 8:48:21" "30-1-08 8:55:17" "30-1-08 9:00:22" ...
>
> I do:
>> delme3 <-  strptime(delme2,format="%d-%m-%y %H:%M:%S")
>
> But then:
>> str(delme3)
> POSIXlt[1:9], format: "2008-01-30 08:48:21" "2008-01-30 08:55:17" ...
>> length(delme3)
> [1] 9
>
> whie
>
>> delme3[1065]
> [1] "2008-06-09 18:25:46"
>
> Where does the length 9 come from? How is it that I can get the 1065th

The list has nine elements: str() is confusiny you here.  It's just the 
same as a data frame: that has (usually) few columns and many rows.

> element of delme3 if the length is just 9? How can I get a vector of POSIX 
> elements with the same length as delme2 so that I can put it in a data.frame?

That must be a POSIXct vector, not a POSIXlt list.

> Thanks!
>
> Agus
> -- 
> Dr. Agustin Lobo
> Institut de Ciencies de la Terra "Jaume Almera" (CSIC)
> LLuis Sole Sabaris s/n
> 08028 Barcelona
> Spain
> Tel. 34 934095410
> Fax. 34 934110012
> email: Agustin.Lobo at ija.csic.es
> http://www.ija.csic.es/gt/obster
>
> ______________________________________________
> 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.
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list