setdiff() not working

487 views
Skip to first unread message

cecilia...@gmail.com

unread,
Sep 1, 2017, 10:17:46 AM9/1/17
to manipulatr
Hi,

I'm having some issues with the setdiff function, it used to work and give me the right output but suddenly it stopped working.

For example:

TheLittleOne<-data.frame(cbind(c(2),c(2))) 
TheBigOne<-data.frame(cbind(c(1,2,3),c(1,2,3))) 
test <- setdiff(TheBigOne, TheLittleOne)

my test object gives me 

  X1 X2
1  1  1
2  2  2
3  3  3

but it should be

  X1 X2
1  1  1
3  3  3

Could someone help me to understand what is going on?

Thanks,
Cecilia

Brandon Hurr

unread,
Sep 1, 2017, 11:24:22 AM9/1/17
to cecilia...@gmail.com, manipulatr
The result you are getting appears to be the case when using the base verison of setdiff. When dplyr/tidyverse is loaded, setdiff works as you expect. 

> TheLittleOne<-data.frame(cbind(c(2),c(2))) 
> TheBigOne<-data.frame(cbind(c(1,2,3),c(1,2,3))) 
> test <- setdiff(TheBigOne, TheLittleOne)
> TheLittleOne
  X1 X2
1  2  2
> TheBigOne
  X1 X2
1  1  1
2  2  2
3  3  3
> test
  X1 X2
1  1  1
2  2  2
3  3  3
> library(tidyverse)
+ ggplot2 2.2.1.9000        Date: 2017-09-01
+ tibble  1.3.3                R: 3.4.1
+ tidyr   0.6.3               OS: macOS Sierra 10.12.6
+ readr   1.1.0              GUI: AQUA
+ purrr   0.2.3.9000      Locale: en_US.UTF-8
+ dplyr   0.7.2.9000          TZ: America/Los_Angeles
+ stringr 1.2.0           
+ forcats 0.2.0           
Conflicts --------------------------------------------------------------------
* filter(),  from dplyr, masks stats::filter()
* lag(),     from dplyr, masks stats::lag()
> ?setdiff()
starting httpd help server ... done
> dplyr::setdiff(TheBigOne, TheLittleOne)
  X1 X2
1  1  1
2  3  3
> setdiff(TheBigOne, TheLittleOne)
  X1 X2
1  1  1
2  3  3


--
You received this message because you are subscribed to the Google Groups "manipulatr" group.
To unsubscribe from this group and stop receiving emails from it, send an email to manipulatr+unsubscribe@googlegroups.com.
To post to this group, send email to manip...@googlegroups.com.
Visit this group at https://groups.google.com/group/manipulatr.
For more options, visit https://groups.google.com/d/optout.

cecilia...@gmail.com

unread,
Sep 1, 2017, 12:16:51 PM9/1/17
to manipulatr, cecilia...@gmail.com
Hi Brandon,

Thank you so much!

Best,
Cecilia
To unsubscribe from this group and stop receiving emails from it, send an email to manipulatr+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages