From Timothy.Keitt@stonybrook.edu  Tue Mar 19 22:29:03 2002
From: Timothy.Keitt@stonybrook.edu (Timothy H. Keitt)
Date: 19 Mar 2002 17:29:03 -0500
Subject: [Rd] should lapply preserve attributes?
In-Reply-To: <Pine.GSO.4.44.0203192128260.24417-100000@auk.stats>
References: <Pine.GSO.4.44.0203192128260.24417-100000@auk.stats>
Message-ID: <1016576943.30316.43.camel@keittlab-6>

On Tue, 2002-03-19 at 16:31, Prof Brian D Ripley wrote:
> On 19 Mar 2002, Timothy H. Keitt wrote:
> >
> > Would it make sense to replace
> >
> > 	names(rval) <- names(X)
> >
> > with
> >
> > 	attributes(rval) <- attributes(X)
> >
> > ?? I can, of course, make a local function for this, but wondered if
> > this change would be useful in general.
> 
> No, it would be positively harmful.  X might be a data frame, or a time
> series .., but rval is only guaranteed to be the same length as X.  If you
> know more, adjust the object returned by lapply.
> 

Yes, nevermind. Ah, tiredness... I realized that's not what I meant
after hitting "send" (and that Brian would catch it before I could reply
to my own email! ;-).

What I want is to apply a function to a list of objects and have the
attributes of the objects copied to the resulting list items, e.g.,

out <- lapply(list(ts1=ts(1:10), ts2=ts(1:5)), sample)

and have 'out' be a list of time series instead of attributeless
vectors. Obviously the solution is to make a function that both permutes
the values and copies the attributes as well.

Tim

-- 
Timothy H. Keitt
Department of Ecology and Evolution
State University of New York at Stony Brook
Stony Brook, New York 11794 USA
Phone: 631-632-1101, FAX: 631-632-7626
http://life.bio.sunysb.edu/ee/keitt/
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


[Rd] should lapply preserve attributes?
Timothy H. Keitt