Skip to content
Prev 60084 / 398502 Next

Creating a factor from a combination of vectors

Hi Yves,

Using your objects, here is a way:


 > cascombo=do.call("paste",c(cas,sep="."))
 > factor(do.call("paste",c(df,sep=".")),levels=cascombo,labels=rownames(cas))
[1] 
Low    <NA>   <NA>   <NA>   <NA>   <NA>   <NA>   <NA>   <NA>   <NA>   <NA> 
  <NA>   Medium <NA>   <NA>
[16] <NA>   <NA>   <NA>   <NA>   <NA>   <NA>   <NA>   <NA>   <NA>   High
Levels: Low Medium High


It uses:
? paste (sep=.) to create the combinations ie 0.0, 10.50, etc.
? do.call to invoke the paste on the columns of the data.frames
? factor specifying existing levels (only those defined by cas data.frame) 
anbd labels

Eric
At 10:12 30/11/2004, Yves Brostaux wrote:
Eric Lecoutre
UCL /  Institut de Statistique
Voie du Roman Pays, 20
1348 Louvain-la-Neuve
Belgium

tel: (+32)(0)10473050
lecoutre at stat.ucl.ac.be
http://www.stat.ucl.ac.be/ISpersonnel/lecoutre

If the statistics are boring, then you've got the wrong numbers. -Edward 
Tufte