[R] searching for elements

Steve Lianoglou mailinglist.honeypot at gmail.com
Wed Jul 15 19:34:37 CEST 2009


One more thing,

>> Error in Ops.factor(sigs[i, 1], p0_recent[j, 1]) :
>> level sets of factors are different
>
> It seems that this particular problem is due to the fact that you  
> are comparing two sets of factors with different levels, which is  
> what the Ops.factor error is saying. But let's make it more clear:
>
> R> f1 <- factor(c('a','b','c'))
> R> f1
> [1] a b c
> > f2 <- factor(c('c','d','e'))
> [1] c d e
> Levels: c d e
> > f1[3] == f2[1]
> Error in Ops.factor(f1[3], f2[1]) : level sets of factors are  
> different


One way to fix would be to ensure all factors have the same levels  
from the get go, like:

It seems that your first problem you're facing looks like you are  
comparing two sets of factors with different levels, which is what the  
Ops.factor error is saying. But let's make it more clear:

R> f1 <- factor(c('a','b','c'), levels=c('a','b','c','d','e'))
R> f2 <- factor(c('c','d','e'), levels=c('a','b','c','d','e'))

R> f1
[1] a b c
Levels: a b c d e
R> f2
[1] c d e
Levels: a b c d e

R> f1[3] == f2[1]
[1] TRUE

--
Steve Lianoglou
Graduate Student: Physiology, Biophysics and Systems Biology
Weill Medical College of Cornell University

Contact Info: http://cbio.mskcc.org/~lianos/contact




More information about the R-help mailing list