[R] newbie lapply question
Prof Brian Ripley
ripley at stats.ox.ac.uk
Wed Dec 5 18:24:43 CET 2007
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)
>  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
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, 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