[R] documentation of intersect() on string vector and num vector and on duplicated elements

Peng Yu pengyu.ut at gmail.com
Wed Dec 2 23:00:16 CET 2009


On Wed, Dec 2, 2009 at 3:51 PM, David Winsemius <dwinsemius at comcast.net> wrote:
> On Dec 2, 2009, at 4:33 PM, Peng Yu wrote:
>
>>> intersect(c(1,3,2),c('1','3'))   # note x is numeric and y is character
>>
>> [1] "1" "3"
>>
>> Apparently, intersect() treats num as string. But this is not
>> documented in the help. Could somebody add it in the future version of
>> R?
>
> It is documented that intersect will return a value of that is same mode as
> its "y" argument. How could it be any more clear?
>
>>
>> Also according to the help, the argument should not have duplicated
>> elements.
>
> That's not what my help page says. It says that "conceptually" they won't
> have them, but immediately thereafter it says:
> "Details
> Each of union, intersect, setdiff and setequal will discard any duplicated
> values in the arguments, and they apply as.vector to their arguments (and so
> in particular coerce factors to character vectors)."
>
> Unfortunately, R does not have a package that will ensure that users will
> read the help pages carefully.

I didn't read Details. Because I was interested in the arguments. The
problem of some R document is that some information should gathered
together are spread into multiple places. In particular, in the help
of intersect, the first line of 'Details' should be merged with
'Argument' to make the help page clear and easy to read.

> --
>
> David
>
>> But I tried the following example, it seems that it doesn't
>> matter where there are duplicated elements or not. Should the help be
>> corrected? Or somebody could provide me with an example that make
>> intersect() fails if there are duplicated elements?
>>
>>> x=c(3,1,2,1,7)
>>> y=c(5,1,4,2,3,8,1)
>>> x
>>
>> [1] 3 1 2 1 7
>>>
>>> y
>>
>> [1] 5 1 4 2 3 8 1
>>>
>>> intersect(x,y)
>>
>> [1] 3 1 2
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> 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.
>
> David Winsemius, MD
> Heritage Laboratories
> West Hartford, CT
>
>




More information about the R-help mailing list