Re: [R] Assigning to a vector while keeping the attributes

2009-02-09 Thread Gabor Grothendieck
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

Re: [R] Assigning to a vector while keeping the attributes

2009-02-09 Thread David Winsemius
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.

[R] Assigning to a vector while keeping the attributes

2009-02-09 Thread Alon Wasserman
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