[R] Combining columns of different length
Petr Pikal
petr.pikal at precheza.cz
Tue Oct 26 14:26:22 CEST 2004
On 26 Oct 2004 at 15:46, Federico Gherardini wrote:
> Hi all,
>
> Simple and direct question....
> Is it possible to add a shorter column to a data frame or matrix in
> such a way that the missing values are replaced with NAs? For example
> suppose I have
>
> 3 2
> 4 2
> 5 8
>
> and I want to add a column
>
> 3
> 3
>
> to get...
>
> 3 2 3
> 4 2 3
> 5 8 NA
Hi
Maybe there is another approach but this shall work
no.r <- nrow(df)
l.v <- length(your.short.vector)
difer <- no.r-l.v
cbind(df,c(your.short.vector,rep(NA,difer)))
Cheers
Petr
>
> Thanks
>
> Federico
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
Petr Pikal
petr.pikal at precheza.cz
More information about the R-help
mailing list