[R] looping over factors

Michael A. Miller mmiller3 at iupui.edu
Fri Jan 30 22:34:00 CET 2004


>>>>> "Samuelson," == Samuelson, Frank* <Samuelson> writes:

    > How does one loop over factors? 

You can loop on the levels of your factor:

> b<-factor(c('caseX','caseY', 'caseZ', 'caseX'))
> b
[1] caseX caseY caseZ caseX
Levels: caseX caseY caseZ
> for ( i in levels(b) ) { print(i) }
[1] "caseX"
[1] "caseY"
[1] "caseZ"
> 


Mike




More information about the R-help mailing list