Wednesday, 15 January 2014

set difference - How not to lose copied elements in setdiff in R? -


I am not in another set that use the setdiff function to remove elements of the first set I am doing But after evaluating setdiff , I get such elements, but they are single values ​​(as if the first set was not in it); Like this:

  & gt; Setdiff (c ("x", "x", "y"), c ("y")) [1] "x"  

Is one of the elements to remove such elements The clever way but in an amount that was in the first set of results of this line?

  & gt; % C (% (c ("x", "x", "y"), [c ("x", "x", "y" C ("Y")) [1] "x" "x"  

reverse To simplify the expression, match % in% , and skip setdiff :

  & gt; X & lt; - c ("x", "x", "y") & gt; X [1] "x" "x" "y" & gt; X [! X% in% c ("y")] [1] "x" "x"  

No comments:

Post a Comment