[R] position of mismatches in all.equal()?

Ivan Calandra ivan.calandra at uni-hamburg.de
Wed Mar 31 15:13:02 CEST 2010


Dear R users,

I would like to compare two dataframes, actually their categorical 
variables (as factors) only (there are 12, from column 1 to 12).
The reason I do that is that I got 2 datasets from two different methods 
and I would like to be sure that each method used the same data (3D 
images) to extract 2 different sets of 3D parameters. Is it clear so far?

So I thought about using all.equal() like this:

test1 <- data.frame(num=1:10, let1=letters[1:10], let2=letters[1:10])
test2 <- data.frame(num=1:10, let1=letters[1:10], let2=letters[c(1:6, 6, 
8:10)])

Since I want to compare only some columns, I do this:
 > all.equal(test1[,1:2], test2[,1:2])
[1] TRUE
 > all.equal(test1[,1:3], test2[,1:3])
[1] "Component 3: Attributes: < Component 2: Lengths (10, 9) differ 
(string compare on first 9) >"
[2] "Component 3: Attributes: < Component 2: 3 string mismatches >"
[3] "Component 3: 1 string mismatch"

If I get TRUE, then everythin's fine. But if not, I just know from the 
output in which column(s) are the mismatches and how many (here 1).
But my datasets are 2000+ rows, and I would like to know the row 
number(s) where mismatches occur.

How can I do that?

Thank you for your help!
Regards,
Ivan

-- 
Ivan CALANDRA
PhD Student
University of Hamburg
Biozentrum Grindel und Zoologisches Museum
Abt. Säugetiere
Martin-Luther-King-Platz 3
D-20146 Hamburg, GERMANY
+49(0)40 42838 6231
ivan.calandra at uni-hamburg.de

**********
http://www.for771.uni-bonn.de
http://webapp5.rrz.uni-hamburg.de/mammals/eng/mitarbeiter.php



More information about the R-help mailing list