Message-ID: <644D9337A02FC24689647BF9E48EC39E08ABB742@drm556>
Date: 2004-01-30T19:08:26Z
From: Samuelson, Frank*
Subject: looping over factors
How does one loop over factors? Perhaps this is a newbie question.
I tried:
> b
[1] caseX caseY caseZ
Levels: caseX caseY caseZ
> length(b)
[1] 3
>
> for (i in b) {
+ print (b == i) ;
+ print (i);
+ }
[1] FALSE FALSE FALSE
[1] 1
[1] FALSE FALSE FALSE
[1] 2
[1] FALSE FALSE FALSE
[1] 3
>
But that strangely doesn't work. I must protest
the implications of the above. i , as an iterator,
is supposed take on values from b, but never is it equivalent
to any of the values in b. The above works correctly for
numbers or arrays of character strings. What's up with factors?
Thanks for any help.
-Frank