Re: [R] How to generate a new factor variable by two other factor variables

2008-11-04 Thread Shuguang Sun
Thanks. It works :) Shuguang On Wed, Nov 5, 2008 at 12:24 AM, Marc Schwartz <[EMAIL PROTECTED]> wrote: > The easiest way is probably to use interaction(): > >> df > factorA factorB > 1 0 0 > 2 0 0 > 3 1 0 > 4 0 1 > 5 1 1 > > > # Note th

Re: [R] How to generate a new factor variable by two other factor variables

2008-11-04 Thread Bert Gunter
Behalf Of Marc Schwartz Sent: Tuesday, November 04, 2008 8:25 AM To: Jorge Ivan Velez Cc: r-help@r-project.org; Shuguang Sun Subject: Re: [R] How to generate a new factor variable by two other factor variables The easiest way is probably to use interaction(): > df factorA factorB 1 0

Re: [R] How to generate a new factor variable by two other factor variables

2008-11-04 Thread Marc Schwartz
The easiest way is probably to use interaction(): > df factorA factorB 1 0 0 2 0 0 3 1 0 4 0 1 5 1 1 # Note the default separator of '.' df$factorC <- with(df, interaction(factorA, factorB)) > df factorA factorB factorC 1 0

Re: [R] How to generate a new factor variable by two other factor variables

2008-11-04 Thread Jorge Ivan Velez
Dear Shuguang, Here are two ways. Perhaps they are not efficient enough, but the work: # Data mydata=read.table(textConnection(" factorA factorB 0 0 0 0 1 0 0 1 1 1"),header=TRUE) closeAllConnections() # Option 1 mydata$factorC=as.factor( apply(mydata