From gz@p@t@w@|nberg @end|ng |rom gm@||@com  Mon May  3 20:48:49 2021
From: gz@p@t@w@|nberg @end|ng |rom gm@||@com (Gustavo Zapata Wainberg)
Date: Mon, 3 May 2021 20:48:49 +0200
Subject: [Rd] Inconsistency in median()
Message-ID: <CAFQ8Lqn=bn6pebC7gv13vHMx2PrApM7_Zo-HrxV+C7oVxjM0EA@mail.gmail.com>

Hi!

I'm wrinting this post because there is an inconsistency when median() is
calculated for even or odd vectors. For odd vectors, attributes (such as
labels added with Hmisc) are kept after running median(), but this is not
the case if the vector is even, in this last case attributes are lost.

I know that this is due to median() using mean() to obtain the result when
the vector is even, and mean() always takes attributes off vectors.

Don't you think that attributes should be kept in both cases? And, going
further, shouldn't mean() keep attributes as well? I have looked in R's
Bugzilla and I didn't find an entry related to this issue.

Please, let me know if you consider that this issue should be posted in R's
bugzilla.

Here is an example with code.

rndvar <- rnorm(n = 100)

Hmisc::label(rndvar) <- "A label for RNDVAR"

str(median(rndvar[-c(1,2)]))

Returns: "num 0.0368"

str(median(rndvar[-1]))

Returns:
 'labelled' num 0.0322
 - attr(*, "label")= chr "A label for RNDVAR"

Thanks in advance!

Gustavo Zapata-Wainberg

	[[alternative HTML version deleted]]



[Rd] Inconsistency in median()
Gustavo Zapata Wainberg