dear r experts: I know its almost surely documented. if d is a data frame median(d) <-- fails (message is "need numeric data") min(d) <-- succeeds, but gives a scalar. mean(d) <-- gives a vector I am wondering whether this could be changed into something more consistent. most naturally, the functions might just always return a vector. of course, if this change were made and if I wanted the old min() and max() behavior on a data frame, I would need to first flatten the data. just a thought... /iaw
min, median, mean on data frame (matrix)
2 messages · ivo welch, Gabor Grothendieck
One can use sapply to get a consistent set of idioms despite the underlying inconsistency of the functions themselves (using the builtin dataset anscombe): sapply(anscombe, median) sapply(anscombe, min) sapply(anscombe, mean)
On 12/28/06, ivo welch <ivowel at gmail.com> wrote:
dear r experts: I know its almost surely documented. if d is a data frame median(d) <-- fails (message is "need numeric data") min(d) <-- succeeds, but gives a scalar. mean(d) <-- gives a vector I am wondering whether this could be changed into something more consistent. most naturally, the functions might just always return a vector. of course, if this change were made and if I wanted the old min() and max() behavior on a data frame, I would need to first flatten the data. just a thought... /iaw
______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.