AndriSignorell / DescTools

Tools for Descriptive Statistics and Exploratory Data Analysis
http://andrisignorell.github.io/DescTools/
86 stars 18 forks source link

Mode of two items vector #124

Closed ArielGC closed 10 months ago

ArielGC commented 1 year ago

Hi everyone,

I encountered an issue while using the DescTools::Mode function in my code. The function works perfectly fine with vectors of length 1 or greater than 2, but when I use it with two-item vectors, it returns NA instead of the expected result.

Examples:

When using DescTools::Mode with a vector of length greater than 2:

DescTools::Mode(c(1,2,1,2)) >> [1] 1 2 >> attr(,"freq") >> [1] 2

When using DescTools::Mode with a two-item vector:

DescTools::Mode(c(1,2)) >> [1] NA >> attr(,"freq") >> [1] 1

As you can see in the second example, I expected to get the mode as c(1, 2) with an attribute frequency of 1, but it returns NA instead.

Any help or suggestions to resolve this issue would be greatly appreciated. Thank you!

PS: I'm using DescTools version 0.99.49

AndriSignorell commented 1 year ago

Your expectation is not reasonable, or would you expect the mode of 1:100 to be 1:100 each with frequency 1? ;-)

I would strongly lean towards the view that if no number in a set of numbers occurs more than once, that set has no mode. So the issue is rather, that Mode(c(1)) returns 1 instead of NA, what will be fixed.

Aggreed?

AndriSignorell commented 10 months ago

Please note, that DescTools::Mode() now returns NA, if x is a vector with unique values.

> DescTools::Mode(c(1,2,1,2))
[1] 1 2
attr(,"freq")
[1] 2
> DescTools::Mode(c(1,2))
[1] NA
attr(,"freq")
[1] NA
> DescTools::Mode(c(1:10))
[1] NA
attr(,"freq")
[1] NA
AndriSignorell commented 10 months ago

@ArielGC please check and close if ok, thnx!