Skip to content

comparing columns in a dataframe

2 messages · Mark Leeds, Baptiste Auguie

#
Hi: you've got to create a setdiff in both directions in order to get the
   lone ones in each column because setdiff is
   not? commutative meaning that setdiff(a,b) does not equal setdiff(b,a). once
   you do that, then
   ( setdiff1 + setdiff2 - intersect )? should equal the? union.
   if it doesn't, that would be weird and more investigation would need to be
   done.
On Apr 4, 2009, Bob Green <bgreen at dyson.brisnet.org.au> wrote:
hello,
     I am hoping for some advice regarding comparing variables from 3
     versions of a spreadsheet which have been combined into a single
     dataframe. The aim is to identify which rows have been changed.
     The dataframe contains 177 rows of data (each cell contains text).
     'intersect' produced a file with 35 rows, 'union' a file with 303
     rows and 'setdiff' a file with 130 rows
     Below is the code that I have started with.
     Ideally I would like to identify the actual row numbers where there
     is difference in the variables (either pairwise or between 3 variables).
     x <- read.csv("c://rec_compare.csv",header=T, as.is=TRUE)
     u <- union(x$rm1, x$redc1)
     write.csv(u,"c:/union_test.csv")
     i <- intersect(x$rm1, x$redc1)
     write.csv(i,"c:/intersect_test.csv")
     sd <- setdiff(x$rm1, x$redc1)
     write.csv(sd,"c:/setdiff_test.csv")
     Any suggestions are appreciated.
     regards
     Bob
     ______________________________________________
     [1]R-help at r-project.org mailing list
     [2]https://stat.ethz.ch/mailman/listinfo/r-help
     PLEASE do read the posting guide
     [3]http://www.R-project.org/posting-guide.html
     and provide commented, minimal, self-contained, reproducible code.

References

   1. mailto:R-help at r-project.org
   2. https://stat.ethz.ch/mailman/listinfo/r-help
   3. http://www.R-project.org/posting-guide.html
#
Hi,

Have you looked at the compare package? It might do what you want (I  
just remember seeing its description on R News recently but I've never  
used it),
Just an idea,


baptiste
On 4 Apr 2009, at 23:45, markleeds at verizon.net wrote:

            
_____________________________

Baptiste Augui?

School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK

Phone: +44 1392 264187

http://newton.ex.ac.uk/research/emag