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

Neha Aggarwal aggarwalneha2000 at gmail.com
Sun Mar 18 16:00:11 CET 2018


Problem I am facing is as follows:

Set A is made of 2 sets x and y
x<-{"P1", "P2", "P3", "P4"}
#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.
for (i in A){
    A<-set_symdiff(i,A)    ###Imp line i need help on

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,

	[[alternative HTML version deleted]]

More information about the R-help mailing list