[R] How to unlist Dates

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Oct 23 12:05:40 CEST 2007


On Tue, 23 Oct 2007, Rees, David  wrote:

> Hi,
>
> I am trying to get a vector of dates that I can use for the xaxis in
> matplot (e.g. axis.Date(1,dates) )
>
> I have a list of dates ... e.g.
>
>> dates
> [[1]]
> [1] "2015-02-15"
>
> [[2]]
> [1] "2015-08-15"
>
> [[3]]
> [1] "2015-11-15"
>
> But when I unlist it I "lose" the Dates and get numbers instead
>
>> unlist(dates)
> [1] 16481 16662 16754
>
> Am I doing something wrong using unlist?

No, that is what it is documented to do:

Value:

      'NULL' or an expression or a vector of an appropriate mode to hold
      the list components.

      The output type is determined from the highest type of the
      components in the hierarchy NULL < raw < logical < integer < real
      < complex < character < list < expression, after coercion of
      pairlists to lists.

Class information should be lost.  You don't give a reproducible example, 
but

do.call("c", dates)

would probably do what you want.

-- 
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