How to take difference of sets when there is an empty subset involved

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to take difference of sets when there is an empty subset involved

Neha Aggarwal
Hello,

Problem I am facing is as follows:

Set A is made of 2 sets x and y
x<-{"P1", "P2", "P3", "P4"}
y<-{}
A<-set(x,y)
#A={{}, {"P1", "P2", "P3", "P4"}}

i need to use A in a recursive loop where i need to take set difference of
A and it 's elements.
Example:
for (i in A){
    print(i)
    A<-set_symdiff(i,A)    ###Imp line i need help on
    print(A)
}

the program is unable to recognise the empty set in the set A. I tried
various  methods in Imp line above:
> A-i
#Output : {{}, {"P1", "P2", "P3", "P4"}}
> set_symdiff(i,A)
Output: {{}, {"P1", "P2", "P3", "P4"}}
> set_symdiff(A,i)
Output: {{}, {"P1", "P2", "P3", "P4"}}

i also tried with set_complement() .But it does not subtract the empty
subset from the bigger set. It seems it doesn't recognise it.
What else can I try ? any pointers/ packages will be great help.

.
Thanks in advance,
Neha

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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 | Threaded
Open this post in threaded view
|

Re: How to take difference of sets when there is an empty subset involved

Duncan Murdoch-2
On 18/03/2018 11:00 AM, Neha Aggarwal wrote:
> Hello,
>
> Problem I am facing is as follows:
>
> Set A is made of 2 sets x and y
> x<-{"P1", "P2", "P3", "P4"}
> y<-{}

Those aren't R code. I think you meant

x <- set("P1", "P2", "P3", "P4")
y <- set()

> A<-set(x,y)
> #A={{}, {"P1", "P2", "P3", "P4"}}
>
> i need to use A in a recursive loop where i need to take set difference of
> A and it 's elements.

This doesn't really make sense.  A is a set of sets.  Its elements are
sets of character strings.  There is no intersection between A and
either of its elements, so the symmetric difference is just the union.
What do you really want?

> Example:
> for (i in A){
>      print(i)
>      A<-set_symdiff(i,A)    ###Imp line i need help on
>      print(A)
> }

That changes A each time through the loop.  Did you really want that?

>
> the program is unable to recognise the empty set in the set A. I tried
> various  methods in Imp line above:
>> A-i
> #Output : {{}, {"P1", "P2", "P3", "P4"}}
>> set_symdiff(i,A)
> Output: {{}, {"P1", "P2", "P3", "P4"}}
>> set_symdiff(A,i)
> Output: {{}, {"P1", "P2", "P3", "P4"}}
>
> i also tried with set_complement() .But it does not subtract the empty
> subset from the bigger set. It seems it doesn't recognise it.
> What else can I try ? any pointers/ packages will be great help.
>

I'm not sure what you are after, but you might want something like

set_symdiff(set(i), A)

or

A - set(i)

Duncan Murdoch

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.