I have a variable with a huge matrix; this variable has some attributes, including smaller matrices.
I want to assign something small (like NA) to this variable, so that I can save memory; but I want to keep the attributes.
Is there some elegant way or do I have to do it in some clumsy way with two assignments, second one with mostattributes?
PS: illustrative example
a <- matrix(1:9,3,3)
attr(a, 'ahoj') <- 1:10
a <- NA # attributes lost, I want assignment which keeps them
The only thing I can think of is to replace the assignment with these 3:
empty_a <- NA
mostattributes(empty_a) <- attributes(a)
a <- empty_a
but that's pretty clumsy way :)