Re: [R] Extending a vector to length n

2009-04-16 Thread Bert Gunter
n Behalf Of hadley wickham Sent: Thursday, April 16, 2009 10:50 AM To: Raubertas, Richard Cc: r-help Subject: Re: [R] Extending a vector to length n Great idea - that's a little faster than my previous approach of setting length() and then re-adding the attributes. Thanks! Hadley On Thu,

Re: [R] Extending a vector to length n

2009-04-16 Thread hadley wickham
> Levels: a >> > > R. Raubertas > Merck & Co > > >> -Original Message- >> From: r-help-boun...@r-project.org >> [mailto:r-help-boun...@r-project.org] On Behalf Of hadley wickham >> Sent: Wednesday, April 15, 2009 10:55 AM >> To: r-help &g

Re: [R] Extending a vector to length n

2009-04-16 Thread Raubertas, Richard
h(b)+1):n] <- NA > bb [1] a Levels: a > R. Raubertas Merck & Co > -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of hadley wickham > Sent: Wednesday, April 15, 2009 10:55 AM > To: r-help > Subj

Re: [R] Extending a vector to length n

2009-04-15 Thread Gabor Grothendieck
This may not be everything you would like but perhaps its sufficient: > structure("length<-"(a, 2), class = class(a)) [1] "2008-01-01" NA Your second example looks ok as is. Can't tell what you don't like about it. On Wed, Apr 15, 2009 at 10:55 AM, hadley wickham wrote: > In general, how can I

Re: [R] Extending a vector to length n

2009-04-15 Thread Richard . Cotton
> In general, how can I increase a vector of length m (< n) to length n > by padding it with m - n missing values, without losing attributes? > The two approaches I've tried, using length<- and adding missings with > c, do not work in general: > > > a <- as.Date("2008-01-01") > > c(a, NA) > [1] "2

[R] Extending a vector to length n

2009-04-15 Thread hadley wickham
In general, how can I increase a vector of length m (< n) to length n by padding it with m - n missing values, without losing attributes? The two approaches I've tried, using length<- and adding missings with c, do not work in general: > a <- as.Date("2008-01-01") > c(a, NA) [1] "2008-01-01" NA >