[R] looping over factors

Robert W. Baer, Ph.D. rbaer at atsu.edu
Fri Jan 30 23:21:10 CET 2004


> 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.

It looks to me like your problem is that your b is a factor, try coercing
it"

b=c("CaseX","CaseY","CaseZ")
b=as.factor(b)
for (i in as.numeric(b)) {print(as.numeric(b)==i);print(i);print(b);}

Rob Baer




More information about the R-help mailing list