From dstr7320 at uni.sydney.edu.au  Fri Jan  8 06:00:04 2016
From: dstr7320 at uni.sydney.edu.au (Dario Strbenac)
Date: Fri, 8 Jan 2016 05:00:04 +0000
Subject: [Rd] Inconsistencies of Fundamental Summary Functions
Message-ID: <SN1PR0101MB1439E442D111FFBFF21D2098CDF60@SN1PR0101MB1439.prod.exchangelabs.com>

Good day,

Functions such as min and max work on a data frame of numbers, but other functions, like median do not. For example,

database <- data.frame(Name = LETTERS[1:3], Amount = 1:3, Price = 4:6)
> min(database[, 2:3])
[1] 1
> mean(database[, 2:3])
[1] NA
> median(database[, 2:3])
Error in median.default(database[, 2:3]) : need numeric data

This observation was made when teaching university students in the first year of their degrees.  Some functions require coercion by using as.matrix but others don't. Surely these simple commands should be consistent.

Also, the documentation for min and max is incomplete. It states "?Numeric? arguments are vectors of type integer and numeric, and logical." It should also mention that it works on data frames, although not when data frames are represented as lists, which can easily be coerced back to data frames.

> min(as.list(database[, 2:3]))
Error in min(as.list(database[, 2:3])) : 
  invalid 'type' (list) of argument

--------------------------------------
Dario Strbenac
PhD Student
University of Sydney
Camperdown NSW 2050
Australia


[Rd] Inconsistencies of Fundamental Summary Functions
Dario Strbenac