[Rd] should lapply preserve attributes?

Timothy H. Keitt Timothy.Keitt@stonybrook.edu
19 Mar 2002 17:29:03 -0500


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