[R] Extending a vector to length n
Gabor Grothendieck
ggrothendieck at gmail.com
Wed Apr 15 17:45:57 CEST 2009
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 <h.wickham at gmail.com> wrote:
> 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
>> length(a) <- 2
>> a
> [1] 13879 NA
>
>
>> b <- factor("a")
>> c(b, NA)
> [1] 1 NA
>> length(b) <- 2
>> b
> [1] a <NA>
> Levels: a
>
> Hadley
>
>
>
> --
> http://had.co.nz/
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list