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
______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to