[R] Fwd: error in duplicated() man page
Juan Gomez
ju@ngomezdu@@o @end|ng |rom gm@||@com
Mon May 13 22:16:43 CEST 2019
---------- Forwarded message ---------
De: Juan Gomez <juangomezduaso using gmail.com>
Date: vie., 10 may. 2019 a las 11:12
Subject: Re: [R] error in duplicated() man page
To: Bert Gunter <bgunter.4567 using gmail.com>
Coming back to my example, which I think illustrates my point, we have
3x2 groups (as specified in MARGIN dimensions) with one cell in each
group. The function looks for an earlier group having the same value.
It does so in column major order (IMHO) and so, it gives a FALSE for
the 2 at coordinates (2,1) and gives TRUE for the one at coordinates
(1,2).
In row major order it would find the "2" in the first row first, and
the "2" in the second row will be considered as duplicated
If the documentation were right, I think the call would be:
duplicatedRowMajor(array(c(1,2,3,2,5,6),c(3,2)), MARGIN=1:2)
[,1] [,2]
[1,] FALSE FALSE
[2,] TRUE FALSE
[3,] FALSE FALSE
El jue., 9 may. 2019 a las 19:15, Bert Gunter
(<bgunter.4567 using gmail.com>) escribió:
>
> Thanks, Martin. I missed the duplication. My apology -- old age is asserting it's presence.
>
> Then my response is: I think the documentation is correct as written:
>
> > a <- matrix(rep(1:3,2), nr=3)
> > a
> [,1] [,2]
> [1,] 1 1
> [2,] 2 2
> [3,] 3 3
>
> > duplicated(a)
> [1] FALSE FALSE FALSE
> > ## Note: Row major by default !
>
> > duplicated(a, MAR = 2)
> [1] FALSE TRUE
>
> Again, apologies for my silly error.
>
> Cheers,
> Bert
>
>
>
> On Thu, May 9, 2019 at 8:56 AM Martin Maechler <maechler using stat.math.ethz.ch> wrote:
>>
>> >>>>> Bert Gunter
>> >>>>> on Thu, 9 May 2019 08:46:15 -0700 writes:
>>
>> > Juan:
>> > No, I think there may be a bug:
>>
>> >> duplicated(array(c(1,2,3,2,5,6),c(3,2)), MARGIN=1:2)
>> > [,1] [,2]
>> > [1,] FALSE TRUE
>> > [2,] FALSE FALSE
>> > [3,] FALSE FALSE
>> > ## This is wrong
>>
>> > ## But if we first define the array...
>> >> a <- array(c(1,2,3,4,5,6), c(3,2))
>> >> duplicated(a, MARGIN = 1:2)
>> > [,1] [,2]
>> > [1,] FALSE FALSE
>> > [2,] FALSE FALSE
>> > [3,] FALSE FALSE
>> > ## This is right
>>
>> Well, the two arrays are different:
>> The first has a '2' instead of a '4'
>> ((and this would not happen if you used 1:6 instead ..))
>>
>> > I'll wait a bit before filing a bug report so that any error I may be
>> > making can be pointed out (note that my R version is NOT current, so I need
>> > to update).
>>
>> >> sessionInfo()
>> > R version 3.5.2 (2018-12-20)
>> > Platform: x86_64-apple-darwin15.6.0 (64-bit)
>> > Running under: macOS Mojave 10.14.4
>>
>> > Matrix products: default
>> > BLAS:
>> > /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
>> > LAPACK:
>> > /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib
>>
>> > locale:
>> > [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
>>
>> > attached base packages:
>> > [1] stats graphics grDevices utils datasets methods base
>>
>> > loaded via a namespace (and not attached):
>> > [1] compiler_3.5.2 tools_3.5.2
>>
>> > Bert Gunter
>>
>> > "The trouble with having an open mind is that people keep coming along and
>> > sticking things into it."
>> > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>>
>>
>> > On Thu, May 9, 2019 at 8:10 AM Juan Gomez <juangomezduaso using gmail.com> wrote:
>>
>> >> I think there is an error in duplicated() help page when it states that:
>> >> "The array method calculates for each element of the sub-array
>> >> specified by MARGIN if the remaining dimensions are identical to those
>> >> for an earlier (or later, when fromLast = TRUE) element (in row-major
>> >> order). "
>> >> Instead of:
>> >> "... (in column-major order)"
>> >>
>> >> For instance:
>> >> duplicated(array(c(1,2,3,2,5,6),c(3,2)), MARGIN=1:2)
>> >> [,1] [,2]
>> >> [1,] FALSE TRUE
>> >> [2,] FALSE FALSE
>> >> [3,] FALSE FALSE
>> >> >
>> >>
>> >> ______________________________________________
>> >> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> >> 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.
>> >>
>>
>> > [[alternative HTML version deleted]]
>>
>> > ______________________________________________
>> > R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> > 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