Bug 16985 - median(integer or logical) return various types of results, while quantile does not
Summary: median(integer or logical) return various types of results, while quantile do...
Status: UNCONFIRMED
Alias: None
Product: R
Classification: Unclassified
Component: Misc (show other bugs)
Version: R 3.3.0
Hardware: Other Other
: P5 minor
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2016-07-08 17:57 UTC by Bill Dunlap
Modified: 2016-07-08 17:57 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bill Dunlap 2016-07-08 17:57:35 UTC
If you give median() a vector of integers or logicals the result is sometimes numeric and sometimes the type of the input data, depending on whether interpolation was needed to compute the median.

  > str(median(c(TRUE,TRUE,TRUE)))
   logi TRUE
  > str(median(c(1:3)))
   int 2
  > str(median(c(TRUE,TRUE,TRUE,TRUE)))
   num 1
  > str(median(1:4))
   num 2.5

quantile(x, 0.5) seems to always return a numeric vector when given logicals or doubles.

This could affect the growing number of people who like to call R functions from C++ code and don't check the type of the result.