[Rd] Inconsistency in median()
Gustavo Zapata Wainberg
gz@p@t@w@|nberg @end|ng |rom gm@||@com
Mon May 3 20:48:49 CEST 2021
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]]
More information about the R-devel
mailing list