Re: [R] newbie lapply question

From: Prof Brian Ripley <>
Date: Wed, 5 Dec 2007 17:24:43 +0000 (GMT)

On Wed, 5 Dec 2007, Ranjan Bagchi wrote:

> Hi --
> I just noticed the following (R 2.6.1 on OSX)
>> lapply(c(as.Date('2007-01-01')), I)
> [[1]]
> [1] 13514
> This is a bit surprising.. Why does lapply unclass the object? Sorry for
> such a basic question, I don't seem able to produce the right google keywords.

Did you not read the help page?:


        X: a vector (atomic or list) or an expressions vector.  Other
           objects (including classed objects) will be coerced by


> as.list(c(as.Date('2007-01-01')))

[1] 13514

BTW, the c() is redundant here: you are concatenating one item only.

As to why as.list() removes the class, read its help page which tells you.

Perhaps if you told us what you are trying to achieve we might be able to help you achieve it.

Brian D. Ripley,        
Professor of Applied Statistics,
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Wed 05 Dec 2007 - 17:40:29 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 05 Dec 2007 - 18:30:17 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.