Questions tagged [set-difference]

The difference between two sets A and B consists of all elements that are in A but not in B.

Set difference is a mathematical operation defined on sets. It is also known as the relative complement of B with respect to A.
If we have two sets, say A and B, their difference A - B is the set of all elements that are in A but not in B.

Several programming languages have built-in features to remove a collection of elements from another collection of elements. When both collections are sets (meaning each element can occur at most once per collection and the order does not matter), this implements set difference.

Source: Wikipedia

197 questions
5
votes
3 answers

R - difference between 2 sets in data frame

I have 2 factor columns, I want to create a third column which tells me what the second one has that the first does not. It's very similar to this post but I'm having trouble going from a df to using setdiff() function. For…
jmich738
  • 1,565
  • 3
  • 24
  • 41
5
votes
1 answer

Array difference as a series of actions

In short: I have two arrays which may be different, and I'll like to get the difference/transformation as a series of "actions" (adds and removes). That is, in a basic example: Current: [a, b, d] Desired: [a, b, c, d] Actions: Add c in position…
nickf
  • 537,072
  • 198
  • 649
  • 721
4
votes
2 answers

Python Numpy get difference between 2 two-dimensional array

Well, I have a simple problem that is giving me a headache, basically I have two two-dimensional arrays, full of [x,y] coordinates, and I want to compare the first with the second and generate a third array that contains all the elements of the…
Pedro Bzz
  • 65
  • 2
  • 7
4
votes
1 answer

R lubridate find non overlapping periods between a continuous time frame and a set of intervals

I've got the following time frame: A <- c('2016-01-01', '2019-01-05') B <- c('2017-05-05','2019-06-05') X_Period <- interval("2015-01-01", "2019-12-31") Y_Periods <- interval(A, B) I'd like to find the non overlapping periods between X_Period and…
Dario Federici
  • 1,228
  • 2
  • 18
  • 40
4
votes
3 answers

Can the following Nested foreach loop be simplified in PowerShell?

I have created a script that loops through an array and excludes any variables that are found within a second array. While the code works; it got me wondering if it could be simplified or piped. $result = @() $ItemArray = @("a","b","c","d") …
AfroBadger
  • 75
  • 6
4
votes
3 answers

rm( ) everything except specific object

Does someone have an idea about how can I remove everything in R except one object? Normally, to remove everything I code: rm(list=ls()) So I tried: rm(c(list=ls()-my_object)) but it didn’t work.
4
votes
2 answers

Vector difference while preserving order

I have two char vectors say {'G', 'K', 'A', 'L', 'P'} and {'K', 'P', 'T', 'M'}. I have to get the difference between these two vectors while preserving the order i.e. {'G', 'A', 'L'}. I am aware of std::set_difference function but that can't be used…
Oliver Blue
  • 677
  • 2
  • 9
  • 22
4
votes
4 answers

Preserving the order in difference between two lists

I have two lists l and l_match. l_match is an empty list. l = ['gtttaattgagttgtcatatgttaataacg', 'tttaattgagttgtcatatgttaataacgg', 'ttaattgagttgtcatatgttaataacggt', 'taattgagttgtcatatgttaataacggta', …
Ssank
  • 3,367
  • 7
  • 28
  • 34
4
votes
2 answers

Is there a difference Ord operator on lists in haskell?

I would like to do set difference between 2 integer lists, which allow repetitions in haskell. So in case of having [1,2,1,4,3] [1,2,4], the difference would be [1,3] Currently I can do it via the normal \\ operator listA \\ listB. But the problem…
user4233758
4
votes
3 answers

Matrix row difference, output a boolean vector

I have an m x 3 matrix A and its row subset B (n x 3). Both are sets of indices into another, large 4D matrix; their data type is dtype('int64'). I would like to generate a boolean vector x, where x[i] = True if B does not contain row A[i,:]. There…
John Manak
  • 13,328
  • 29
  • 78
  • 119
4
votes
1 answer

Capturing matching and non-matching values between two dataframes in R

I've done quite a bit of reading on this but I've not been able to get an answer that works yet. I've been using the setdiff function in R to look at the number of matches between two dataframes. I know that I have 71 out of 200 observations…
Thirst for Knowledge
  • 1,606
  • 2
  • 26
  • 43
4
votes
5 answers

Set difference with XPath 1.0 - how do I get .//table without .//table//table?

I'm trying to find all the tables below my current node without also including the nested tables. In other words, if I have this, i want to find "yes" and not "no":