Take this as an example:> a=data.frame(col1=c(1,2,3,4,5), col2=c("my","beloved","daughter","son","wife"))> b=data.frame(col1=c(1,2,4),col2=c("my","beloved","son"))> acol1 col2 1 1 my 2 2 beloved 3 3 daughter 4 4 son 5 5 wife> bcol1 col2 1 1 my 2 2 beloved 3 4 son As you can see in b is equal to a with exception of lines of a with col1= 3 and col1=5 that are missing. How can I obtain a third dataframe made of the missing lines only, e.g.> ccol1 col2 1 3 daughter 2 5 wife Ciao Vittorio
try this (presuming that you want to find the missing lines based on
the 2nd column of the data frames):
a[!a$col2 %in% b$col2, ]
I hope it helps.
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://www.med.kuleuven.be/biostat/
http://www.student.kuleuven.be/~m0390867/dimitris.htm
----- Original Message -----
From: "Vittorio" <vdemart1 at tin.it>
To: <r-help at stat.math.ethz.ch>
Sent: Friday, October 07, 2005 10:02 AM
Subject: [R] finding missing lines...
> Take this as an example:
>
>> a=data.frame(col1=c(1,2,3,4,5), col2=c
>
("my","beloved","daughter","son","wife"))
>> b=data.frame(col1=c(1,2,4),
> col2=c("my","beloved","son"))
>> a
> col1 col2
> 1 1 my
> 2
> 2 beloved
> 3 3 daughter
> 4 4 son
> 5 5 wife
>> b
>
> col1 col2
> 1 1 my
> 2 2 beloved
> 3 4 son
>
> As you can
> see in b is equal to a with exception of lines of a with col1= 3 and
> col1=5 that are missing.
>
> How can I obtain a third dataframe made of
> the missing lines only, e.g.
>
>> c
> col1 col2
> 1 3 daughter
> 2
> 5 wife
>
> Ciao
> Vittorio
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
Vittorio, you can also code sthing like this:> ind<-(setdiff(b,a))$col1you have what is common in a and b, and then you take the opposite in a :> a[-ind,]col1 col2 3 3 daughter 5 5 wife hope this helps, florence. On 10/7/05, Vittorio <vdemart1@tin.it> wrote:> > Take this as an example: > > > a=data.frame(col1=c(1,2,3,4,5), col2=c > ("my","beloved","daughter","son","wife")) > > b=data.frame(col1=c(1,2,4), > col2=c("my","beloved","son")) > > a > col1 col2 > 1 1 my > 2 > 2 beloved > 3 3 daughter > 4 4 son > 5 5 wife > > b > > col1 col2 > 1 1 my > 2 2 beloved > 3 4 son > > As you can > see in b is equal to a with exception of lines of a with col1= 3 and > col1=5 that are missing. > > How can I obtain a third dataframe made of > the missing lines only, e.g. > > > c > col1 col2 > 1 3 daughter > 2 > 5 wife > > Ciao > Vittorio > > ______________________________________________ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html >[[alternative HTML version deleted]]