[R] documentation of intersect() on string vector and num vector and on duplicated elements
Peter Ehlers
ehlers at ucalgary.ca
Thu Dec 3 00:36:15 CET 2009
Peng Yu wrote:
> 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.
----------------------------
I take very strong exception to this suggestion and to the
whining tone of the comment. If an R user can't be bothered
to read *all* of a help page, then that's his problem, not R's.
Since it is IMHO too common in this forum to see complaints
about the documentation, let me just say this:
I personally find the documentation of (base) R very, very
good to excellent and I think that R-Core deserve a big
pat on the back for their efforts to be as informative as
possible with the help system. Probably my most used
R function is "?" and I particularly like the
arguments/details/value etc layout.
End of rant.
-Peter Ehlers
>
>> --
>>
>> 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
>>
>>
>
> ______________________________________________
> 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.
>
>
More information about the R-help
mailing list