klaus.hermann@metagen.de
2003-Apr-01 15:25 UTC
[Rd] computation with vectors of length 0 (PR#2716)
Full_Name: Klaus Hermann Version: 1.5.0 OS: SUNRAY - Unix Submission from: (NULL) (213.61.59.254) if we produce a numeric vector of length 0 and want compute the sum over its elements the sum function returns 0 - this is obviously misleading. Better would be to return NA and give a corresponding warning. There should be a unified strategy to handle vectors of length 0. For example the functions sum, mean, sd handle such vectors in a different way example: classfreq <- c(3,3,3,3); classfreq <- classfreq[classfreq != 3]; sum(classfreq); mean(classfreq); sd(classfreq);
Prof Brian Ripley
2003-Apr-01 17:13 UTC
[Rd] computation with vectors of length 0 (PR#2716)
Your report is `obviously misleading', as you seem unaware of the standard mathematical definitions. You also seem unaware that R statements are terminated by a newline, so you have a while series of empty statements and should not have the semicolons. The sum of an empty vector is 0, by definition. The mean of an empty vector is 0/0 = NaN, by definition. The variance and hence the standard deviation are undefined unless n >= 1. None of them are missing, so it would be incorrect to return NA. On Tue, 1 Apr 2003 klaus.hermann@metagen.de wrote:> Full_Name: Klaus Hermann > Version: 1.5.0 > OS: SUNRAY - Unix > Submission from: (NULL) (213.61.59.254) > > > if we produce a numeric vector of length 0 and want compute the sum over its > elements > the sum function returns 0 - this is obviously misleading. Better would be to > return > NA and give a corresponding warning. > There should be a unified strategy to handle vectors of length 0.There is: to use the standard mathematical definitions. One could debate what var(numeric(0)) should be, but we decided that was most consistently an error.> For example the functions sum, mean, sd handle such vectors in a different way > > example: > > classfreq <- c(3,3,3,3); > classfreq <- classfreq[classfreq != 3]; > > sum(classfreq); > mean(classfreq); > sd(classfreq);-- Brian D. Ripley, ripley@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Apparently Analagous Threads
- What has been swapped out?
- Decoding only a certain frame results in different values than when decoding the entire file
- Decoding only a certain frame results in different values than when decoding the entire file
- serial subtraction within a vector
- Decoding only a certain frame results in different values than when decoding the entire file