[R] Counting two factors at the same time

Fabrice DELENTE fdelente at mail.cpod.fr
Fri Jan 22 20:07:25 CET 2010


> Here's another R-way:
> 
> > lets<-factor(c( 'A', 'B', 'A', 'C', 'B', 'D', 'B'))
> # you did say they were factors, right?
> > nums <- factor(c('1', '2', '2', '3', '2', '2', '3'))
> > lets=="B"
> [1] FALSE  TRUE FALSE FALSE  TRUE FALSE  TRUE
> > sum(lets=="B" & nums=="2")
> [1] 2

Thanks very much, it will save me :^)

As I am a beginner in R, I have a little trouble understanding factors. Can
they be used interchangeably with lists, or are they a different data-type?
Can I do on factors everything that I can do on lists?

Thanks again!

-- 
Fabrice DELENTE



More information about the R-help mailing list