Actually you got it, the data sets you created are a perfect example (row#1 and 
row#2 in DF1 have the same V1 and differ only in V2) , but here is the problem:
row#2 in DF1 exists in DF1 and not in DF2, however it does not show in the 
Difference. It seems to me that both V1 and V2 should be considered when 
calculating the difference.



----- Original Message ----
From: Jorge Ivan Velez <[EMAIL PROTECTED]>
To: joseph <[EMAIL PROTECTED]>
Sent: Sunday, September 14, 2008 11:14:11 AM
Subject: Re: [R] difference of two data frames



Hi Joseph,

I'm not sure if I understood your point, but try this:

# Data sets
DF1= data.frame(V1=c(1,1,2,3,3,4,5,5,6), V2= letters[1:9])
DF2= data.frame(V1=1:3, V2= letters[1:3])

# Difference
DF1[! DF1$V1 %in% DF2$V1,]



HTH,

Jorge




On Sun, Sep 14, 2008 at 1:57 PM, joseph <[EMAIL PROTECTED]> wrote:

Hi Jorge
both commands work; 
can you extend it to several coulmns?  the reason I am asking is that in my 
real data the uniqueness of the rows is made of all the columns; in other words 
V1 might have duplicates.
Thanks




----- Original Message ----
From: Jorge Ivan Velez <[EMAIL PROTECTED]>
To: joseph <[EMAIL PROTECTED]>

Cc: r-help@r-project.org
Sent: Sunday, September 14, 2008 10:23:33 AM
Subject: Re: [R] difference of two data frames



Hi Joseph,

Try this:


DF1[!DF1$V1%in%DF2$V1,]

subset(DF1,!V1%in%DF2$V1)


HTH,

Jorge


On Sun, Sep 14, 2008 at 12:49 PM, joseph <[EMAIL PROTECTED]> wrote:

Hello
I have 2 data frames DF1 and DF2 where DF2 is a subset of DF1:
DF1= data.frame(V1=1:6, V2= letters[1:6])
DF2= data.frame(V1=1:3, V2= letters[1:3])
How do I create a new data frame of the difference between DF1 and DF2
newDF=data.frame(V1=4:6, V2= letters[4:6])
In my real data, the rows are not in order as in the example I provided.
Thanks much
Joseph



       [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


      
        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to