Unexpected behavior for setdiff function in R

0 votes
According to my understanding, the setdiff() function analyses two vectors and returns the elements that are present in one vector but absent in the other. Given these vectors, if that's the case, then...

item 1 - c (1,2,3)
thing2 <- c(2,3,4)\sthing3 <- c(1,2,3)\s...my here's results.

SetDifference(Thing1,Thing2) > [1] 1

SetDifference(Thing2,Thing3) > [1] 4

SetDifference(Thing1,Thing3) > Numeric (0)
Shouldn't comparing item 1 and item 2 yield the same results as comparing item 2 and item 3? How can we get a symmetric set difference result that looks like a "outer join" such that we can see all the elements that would be missing if we unioned thing1 and thing2? I would value data more than I would like to know R's functionality. tables move closer. I believe that setdiff() analyses two vectors and outputs the elements that are present in one vector but absent in the other.
Jun 22 in Data Science by avinash
• 1,840 points
23 views

1 answer to this question.

0 votes
Asymmetric difference is provided by 18 setdiff. It fulfils its purpose in this instance.

Shouldn't comparing item 1 and item 2 yield the same results as comparing item 2 and item 3?

Okay, no. But the outcomes will be the same as if thing3 and thing2 were compared. Order is important. Think about your first two instances:

What does thing1 include that thing2 does not, according to the first example?

more setdiff (thing1, thing2)

[1] 1

You could try the reverse, what is in thing2 that is not in thing1?

> setdiff(thing2, thing1)

[1] 4

But it looks to me like the question you're asking is:

What elements of thing1 and thing2 are not shared?

Which is the same as:

What elements are in the union of thing1 and thing2, but
answered Jun 24 by Sohail
• 2,960 points

Related Questions In Data Science

0 votes
1 answer

How to implement Knn-algorithm without using k-nn function in r?

I created an example that demonstrates the ...READ MORE

answered Jun 24 in Data Science by Sohail
• 2,960 points
14 views
0 votes
1 answer

Problem with sample function in R

The first time works, but after that, ...READ MORE

answered Jun 24 in Data Science by Sohail
• 2,960 points
18 views
0 votes
0 answers
0 votes
0 answers

In R, how to get an object's name after it is sent to a function?

I'm trying to find the opposite of ...READ MORE

Jul 5 in Data Science by avinash
• 1,840 points
8 views
0 votes
1 answer

Big Data transformations with R

Dear Koushik, Hope you are doing great. You can ...READ MORE

answered Dec 18, 2017 in Data Analytics by Sudhir
• 1,610 points
437 views
0 votes
2 answers

Transforming a key/value string into distinct rows in R

We would start off by loading the ...READ MORE

answered Mar 26, 2018 in Data Analytics by Bharani
• 4,660 points
482 views
0 votes
1 answer

Finding frequency of observations in R

You can use the "dplyr" package to ...READ MORE

answered Mar 26, 2018 in Data Analytics by Bharani
• 4,660 points
4,352 views
0 votes
1 answer

Left Join and Right Join using "dplyr"

The below is the code to perform ...READ MORE

answered Mar 27, 2018 in Data Analytics by Bharani
• 4,660 points
504 views
0 votes
1 answer

How to make loop for one-at-a time logistic regression in R?

You're probably looking for something similar to ...READ MORE

answered Jun 20 in Data Science by Sohail
• 2,960 points
58 views
0 votes
1 answer

rnorm function in R - Usage

y = rnorm(12, rep(c(1,2,1), each=4, 0.2)) I can ...READ MORE

answered Jun 24 in Data Science by Sohail
• 2,960 points
27 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP