[Rd] Suggestion for all.equal.factor

McGehee, Robert Robert.McGehee at geodecapital.com
Thu Jun 22 01:13:27 CEST 2006


R-Devel,
all.equal.factor gives a warning message when comparing vectors of
factors of different lengths. I suspect this to be unintentional as I
believe tests of valid factors should be comparable without a warning.

For example:
> x1 <- as.factor(LETTERS)
> x2 <- as.factor(LETTERS)[1:10]
> all.equal.factor(x1, x2)
[1] "Lengths: 26, 10"

[2] "Lengths (26, 10) differ (string compare on first 10)"

Warning message:
longer object length
	is not a multiple of shorter object length in: nax != nay 

If it is not improper to compare objects of different lengths, I would
like to propose the following patch that removes this warning without
otherwise changing the behavior of all.factor.equal.

-     if(n <- sum(nax != nay))
+     if(n <- length(nax) == length(nay) && sum(nax != nay))

My assumption here is that it is not meaningful to compare NA mismatches
on vectors of different lengths. Also, if the vectors do have different
lengths then this will be reported in the first line anyway.

Best,
Robert

> R.version
               _                         
platform       i386-pc-mingw32           
arch           i386                      
os             mingw32                   
system         i386, mingw32             
status                                   
major          2                         
minor          3.1                       
year           2006                      
month          06                        
day            01                        
svn rev        38247                     
language       R                         
version.string Version 2.3.1 (2006-06-01)

Robert McGehee
Quantitative Analyst
Geode Capital Management, LLC
53 State Street, 5th Floor | Boston, MA | 02109
Tel: 617/392-8396    Fax:617/476-6389
mailto:robert.mcgehee at geodecapital.com



This e-mail, and any attachments hereto, are intended for us...{{dropped}}



More information about the R-devel mailing list