Try this:
a <- structure(1:3, x = 3)
b <- "attributes<-"(11:15, attributes(a))
dput(b)
On Mon, Feb 9, 2009 at 7:09 AM, Alon Wasserman wrote:
> Hi,
> I would like to know how to assign values to a whole vector while keeping
> its attributes. For example, say I have
> a <- structure(1:3,x=3)
> and
Not sure what "a" really is. It's not a vector or a list according to
the R interpreter.
> a <- structure(1:3,x=3)
> mode(a)
[1] "numeric"
> is.vector(a)
[1] FALSE
> is.list(a)
[1] FALSE
Experimentation shows that simple indexing provides the functionality
you request while append does not.
Hi,
I would like to know how to assign values to a whole vector while keeping
its attributes. For example, say I have
a <- structure(1:3,x=3)
and I want to change the values to 2:4. If I do, a <- 2:4, the attribute x
will be lost. I have a workaround for this case, which is to use subset
assignment
3 matches
Mail list logo