[R] comparing columns in a dataframe

Bob Green bgreen at dyson.brisnet.org.au
Sun Apr 5 00:33:02 CEST 2009


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




More information about the R-help mailing list