[R] Combining columns of different length

Yves Magliulo ym at climpact.com
Tue Oct 26 14:27:37 CEST 2004


hi,

something like :
toto is your data.frame
toto=
V1  V2	
3   2
4   2
5   8

and tata=
3
3

so to do what you want make 
cbind(toto,c(tata,rep(NA,len=(length(toto$V1)-length(tata)))))

maybe there is a easier way but it's work!

-- 
------
Yves Magliulo <ym at climpact.com>
R&D Engineer, CLIMPACT

Tel.   : +33 (0) 1 44 27 34 31
Fax.   : +33 (0) 1 44 27 49 96 
Universite Pierre et Marie Curie
Boite 101 - Tour 45 - 5eme etage - Couloir 45/46
4 place Jussieu, 75252 Paris CEDEX 05, France

Le mar 26/10/2004 à 15:46, Federico Gherardini a écrit :
> 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
> 
> 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




More information about the R-help mailing list