Re: [R] Compare two dataframes

2010-12-18 Thread Petr Savicky
Hi Mark: > However, if the dataframe contains non-unique rows (two rows with > exactly the same values in each column) then the unique function will > delete one of them and that may not be desirable. In order to get information about equal rows between two dataframes without removing duplicated

Re: [R] Compare two dataframes

2010-12-17 Thread Mark Na
Hi Petr, Many thanks for your help. I like your solution because (and I did not know this) the unique function works on ALL the data at once (i.e., across all of the columns) which means I don't have to make a unique ID field by pasting together all of the rows or run through all of the columns it

Re: [R] Compare two dataframes

2010-12-17 Thread Petr Savicky
On Thu, Dec 16, 2010 at 01:02:29PM -0600, Mark Na wrote: > Hello, > > I have two dataframes DF1 and DF2 that should be identical but are not > (DF1 has some rows that aren't in DF2, and vice versa). I would like > to produce a new dataframe DF3 containing rows in DF1 that aren't in > DF2 (and simi

Re: [R] Compare two dataframes

2010-12-16 Thread Michael Bedward
Hello Mark, This is how I do it but it's longer than your code :) unique.rows <- function (df1, df2) { # Returns any rows of df1 that are not in df2 out <- NULL for (i in 1:nrow(df1)) { found <- FALSE for (j in 1:nrow(df2)) { if (all(df1[i,] == df2[j,])) { found <- T