Skip to content
Prev 7102 / 63421 Next

should lapply preserve attributes?

On Tue, 2002-03-19 at 16:31, Prof Brian D Ripley wrote:
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