Removing data frame from another data frame

For some reason I am not able to remove a dataframe that is a subset of another dataframe. I've searched all around but this doesn't seem to be answered anywhere, which I find a bit strange. So if B is a dataframe that is a subset of A, how do I remove the entire B dataframe from the A dataframe. I've only been able to find methods to remove rows and specific columns but not the entire dataframe.

Use dplyr::anti_join()

anti_join()
return all rows from x where there are not matching values in y, keeping just columns from x.

If you need more specific help, please provide a proper REPRoducible EXample (reprex) illustrating your issue.

I'm trying to keep specific variables (not rows). So in the following code, I would like to keep colums 3 and 4 without explicitly stating 3 and 4 (since my data frame has 162 variables)

a <- rnorm(100)
b <- a + rnorm(100)
c <- as.data.frame(cbind(a, b, a+b, a*b))
d <- select(c, 1:2)

Your example is not reproducible since selec() is not a base R function and you are not including a library call, but I'm going to assume it is dplyr::select(), is this what you mean?

library(tidyverse)

a <- rnorm(100)
b <- a + rnorm(100)
c <- as.data.frame(cbind(a, b, a+b, a*b))
d <- select(c, 1:2)

c %>% 
    select(-!!names(d))
#>              V3            V4
#> 1   -1.22719221  0.3038326119
#> 2    6.27336214  8.8600978655
#> 3    1.14139758  0.3207289136
#> 4    3.90941474  3.7669771055
#> 5    3.44082884  2.8970009313
#> 6    0.41465516 -0.0204190627
#> 7   -2.18893174  0.8990520292
#> 8    2.27302588  1.0264267635
#> 9    2.18476504  0.7976621752
#> 10   3.74638997  3.4453856493
#> 11   2.90404900  1.6512349461
#> 12   1.05221887  0.1692455658
#> 13   0.56270693 -0.1418796260
#> 14   2.57441469  1.5084953871
#> 15  -0.85615387  0.0271579586
#> 16   1.70309212  0.5832269683
#> 17  -3.44797640  2.9719017540
#> 18   1.25900774 -0.7329668850
#> 19  -2.03047760  0.9726788104
#> 20  -2.23749598  1.2493428181
#> 21   0.86056877 -0.4619442314
#> 22  -3.92508825  3.8427061193
#> 23   5.77211089  8.2343441978
#> 24   3.07272824  2.0575009128
#> 25   0.06734424 -0.0182042841
#> 26  -0.83018569  0.1678562931
#> 27   0.79063859 -0.0402782424
#> 28  -1.25002824  0.3901933817
#> 29  -3.13816881  2.0831057910
#> 30  -1.55094191  0.0208255482
#> 31   1.34175686 -0.0346549358
#> 32  -0.01371880 -0.0076808986
#> 33  -1.89513370  0.4538133426
#> 34   2.14380582  1.0655054648
#> 35  -1.18341889  0.3234954705
#> 36   1.74264059  0.2723482594
#> 37  -3.61016238  2.7034380228
#> 38  -2.20922493  0.4487558451
#> 39  -0.43378955 -0.4579949722
#> 40  -1.92335451  0.9244466708
#> 41   0.47544971  0.0563374307
#> 42  -1.54916967  0.3384945388
#> 43   2.81248815  1.5422222415
#> 44  -1.41903857  0.3196446755
#> 45  -4.03142986  3.9984766592
#> 46   1.55547943  0.5919991054
#> 47   0.08283129 -0.0002124066
#> 48  -3.38903046  2.8556441707
#> 49  -2.55541201  1.5257743728
#> 50   2.08610404  1.0861824856
#> 51  -0.93471920 -0.5684740111
#> 52  -6.36196303  9.4478098684
#> 53  -3.27248962  2.6207377951
#> 54  -3.78346481  2.7703264988
#> 55   1.62192239  0.6461546395
#> 56   2.73404862  1.5330648669
#> 57  -3.79402614  3.3506127226
#> 58   0.49375821 -0.6320113640
#> 59   2.48122970  1.4704522051
#> 60  -1.29597157  0.2998424328
#> 61   0.43939735 -0.1068534744
#> 62   1.83165200  0.8239987612
#> 63  -2.17269074  1.0487791223
#> 64   1.00079419  0.1660368503
#> 65   1.73821796  0.7479165015
#> 66   0.86510337 -0.3339242497
#> 67   1.49956988  0.3352637130
#> 68   3.02793316  1.8380806875
#> 69  -3.51916112  3.0102169787
#> 70   0.78228283 -0.4852991266
#> 71  -3.09803432  2.1855625649
#> 72   4.23062646  4.4745309303
#> 73  -1.19440002  0.0046243851
#> 74   2.94179340  2.0511677607
#> 75  -2.74728424  1.5630626996
#> 76   4.82232970  5.3984331036
#> 77  -0.64202463 -0.0583391509
#> 78   4.12512467  3.2993736684
#> 79   0.84132062 -0.0062360709
#> 80   4.52122161  4.3343093892
#> 81   1.11182126  0.2151528243
#> 82  -0.29473190 -0.3071640881
#> 83   1.01715587  0.1855131465
#> 84   1.29580775  0.2383775820
#> 85   2.99934744  1.9001294329
#> 86   2.77345327  1.0375963589
#> 87   3.65171396  2.2930470103
#> 88  -2.00942032  0.9910032929
#> 89   2.80135974  1.6749475388
#> 90  -2.31729027  1.3216570361
#> 91  -0.25625125 -0.0010730017
#> 92  -1.43239173  0.5076117428
#> 93   1.57992958  0.6188132044
#> 94  -3.19361089  2.5492154121
#> 95  -0.67838535  0.1149260648
#> 96   0.17274678 -0.0064137734
#> 97  -3.42481581  2.7201537417
#> 98   1.47530941  0.3446494186
#> 99   1.15610988  0.3229918500
#> 100 -2.25531022  1.1585870096

Created on 2020-01-06 by the reprex package (v0.3.0.9000)

Yes it was. Thanks for the response.

I've been using 'r -!!name()', I wonder why the function requires 2 !!

I was using -!names() and that didn't seem to work.

The rlang operator for unquoting is !! not ! (negation operator)