Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 16th, 2012  |  syntax: None  |  size: 0.67 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Combine multiple categorical variables in one dummy variable
  2. agegroup{<20,20-30,>03}    
  3. disease.level{0,1,2},  
  4. performance{<60, >=60}
  5.        
  6. > ff <- expand.grid(agegroup=factor(c("<20","20-30",">30")),
  7.        disease.level=factor(0:2),performance=factor(c("<60",">=60")))
  8. > combfac <- with(ff,interaction(agegroup,disease.level,performance))
  9. > combfac
  10.  [1] <20.0.<60    20-30.0.<60  >30.0.<60    <20.1.<60    20-30.1.<60
  11.  [6] >30.1.<60    <20.2.<60    20-30.2.<60  >30.2.<60    <20.0.>=60  
  12. [11] 20-30.0.>=60 >30.0.>=60   <20.1.>=60   20-30.1.>=60 >30.1.>=60  
  13. [16] <20.2.>=60   20-30.2.>=60 >30.2.>=60  
  14. 18 Levels: <20.0.<60 20-30.0.<60 >30.0.<60 <20.1.<60 20-30.1.<60 ... >30.2.>=60