[R] substract 2 data.frames

Jinyan Huang jinyan.fr at gmail.com
Sun Feb 27 21:33:25 CET 2011


I think paste all column together, then using a %in% b.
Maybe others have better solution.

On Sun, Feb 27, 2011 at 9:29 PM, Nicolas Gutierrez <nicolasg at uw.edu> wrote:
> Hi!
>
> I have 2 data.frames: "fish" and "popn":
>
>>fish
>
>   xloc yloc id birth  size weight  energy gonad
> 20   15   15 54   -60 107.9   63.0 15952.9   8.0
> 21   15   15 32   -60 105.1   61.4 15538.8   7.8
> 91    4   43 96   -60 118.9   69.4 17573.2   8.8
> 71   32    4 64   -60 121.6   71.0 17976.0   9.0
> 34    2   64 20   -60 116.2   67.9 17173.0   8.6
> 95    6   20 58   -60 106.5   62.2 15738.3   7.9
> 97    7   81 89   -60 104.5   61.1 15449.6   7.7
> 94    5   30 74   -60 103.0   60.1 15217.1   7.6
> 45   26   28 92   -60  98.6   57.6 14566.2   7.3
> 59   29   37 42   -60  98.1   57.3 14492.0   7.2
>
>>popn
>
>   xloc yloc id birth  size weight  energy gonad
> 20   15   15 54   -60 107.9   63.0 15952.9   8.0    #delete
> 21   15   15 32   -60 105.1   61.4 15538.8   7.8    #delete
> 90    4   43 28   -60  74.6   43.6 11027.3   5.5
> 91    4   43 96   -60 118.9   69.4 17573.2   8.8    #delete
> 71   32    4 64   -60 121.6   71.0 17976.0   9.0    #delete
> 34    2   64 20   -60 116.2   67.9 17173.0   8.6    #delete
> 95    6   20 58   -60 106.5   62.2 15738.3   7.9    #delete
> 97    7   81 89   -60 104.5   61.1 15449.6   7.7    #delete
> 94    5   30 74   -60 103.0   60.1 15217.1   7.6    #delete
> 45   26   28 92   -60  98.6   57.6 14566.2   7.3    #delete
> 59   29   37 42   -60  98.1   57.3 14492.0   7.2    #delete
> 44   25   82 59   -60  97.6   57.0 14427.3   7.2
> 57   29   15 46   -60  96.4   56.3 14252.7   7.1
> 61    3   80 48   -60  96.4   56.3 14243.3   7.1
> 86   38   67 39   -60  91.3   53.3 13493.6   6.7
>
> And I need to delete the columns in "fish" to the data.frame "popn" as
> follows:
>
>> new.popn
>
>   xloc yloc id birth  size weight  energy gonad
> 90    4   43 28   -60  74.6   43.6 11027.3   5.5
> 44   25   82 59   -60  97.6   57.0 14427.3   7.2
> 57   29   15 46   -60  96.4   56.3 14252.7   7.1
> 61    3   80 48   -60  96.4   56.3 14243.3   7.1
> 86   38   67 39   -60  91.3   53.3 13493.6   6.7
>
> And I need this within loops, so I can't do it "manually". Any guidance??
>
> THANKS!
>
> Nico
>
> ______________________________________________
> R-help at 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.
>



More information about the R-help mailing list